Utilizando count y group by en mysql

En este ejemplo de mysql utilizaremos el count y group by para contar la cantidad de personas que tenemos en la base de datos y agruparlas por sexo.

aqui el codigo:

CREATE TABLE pruebas.personas{
id int unsigned not null autoincrement,
nombre varchar(15) not null,
apellido varchar(12) not null,
cedula int unsigned not null,
#COLLLL__ ZEROFILL = QUE RELLENE CON 0 LOS ESPACIOS DISPONIBLES A LA IZQUIERDA EJEMPLO  en un int(3) el valor 3 = 003
edad tinyint unsigned not null,
ciudad varchar(25) not null,
pais varchar(25) not null,
PRIMARY KEY (id);

}ENGINE = InnoDB;



UPDATE personas set codigopostal = 47001 where id <> 10;

select * from personas order by id;
#count el numero de personas
select count(*) from personas;

select count(edad) from personas;

#group by agrupando por sexo
select sexo, count(*) from personas group by sexo;


MYSQL

Comentarios

Populares

Buscar en este blog