Actividad 1-B

Comandos MySQL para manejo fechas 

Manejo de fechas

Select Current_Date();

Select Year(Current_Date()), Month(Current_Date()), day(Current_Date());

Select date_add(Current_Date(), interval 15 day);

Select date_add(Current_Date(), interval 3 month);

Select date_add(Current_Date(), interval 3 year);

select datediff(current_date(), '1968-07-15');

select datediff('1968-07-15', current_date());

select * from ejercicio;

-Consultas con fechas

Consultar cuantos años tienen

Select Nombre, Year(Current_date()) - year(nacimiento) 'Edad' From Ejercicio;

Contar cuantas personas nacieron entre 1960 y 1969

Select Count(*) From Ejercicio Where Year(Nacimiento) Between 1960 And 1969;

Visualizar toda la información de las personas que tienen entre 33 y 38 años

Select * From Ejercicio Where Year(Current_date()) - year(nacimiento) Between 33 and 38;

Contar cuantas personas tienen <= 38 años y su sexo es mujer

Select Count(*) From Ejercicio Where Year(Current_date()) - year(nacimiento) <= 38 and sexo = 'Mujer';

Hora actual del sistema

Select Current_Time();

Select Hour(Current_Time()), Minute(Current_Time()), Second(Current_Time());

Select now();

Otros comandos MySQL 

Create table Producto(Codigo int auto_increment, nombre char(30) not null, Precio float unsigned, primary key PK_Producto (codigo));

Insert into Producto(nombre, precio) values ('Camisa', 25000), ('Pantalon', 45000);

Insert into Producto(nombre, precio) values ('Chaqueta', -100000);

Select * From Producto;

update Producto set Precio = 100000 where codigo = 3;

Tee: Manejo de fechas


© 2018 Jhon Alejandro Guevara Giraldo, Ingeniero de Sistemas, Medellín-Colombia.
Creado con Webnode
¡Crea tu página web gratis! Esta página web fue creada con Webnode. Crea tu propia web gratis hoy mismo! Comenzar