0% found this document useful (0 votes)
23 views

Create Database If Not Exists Prueb - 1

1) A database named "pruebas" is created and a table named "tblUsuarios" is created within it to store user data including ID, name, gender, level, phone, brand, company, balance, and active status. 2) The table is populated with 21 entries containing user information. 3) A number of queries are then written to select, filter, aggregate and order the user data in various ways such as by gender, brand, company, level, balance and more.

Uploaded by

Lucas Molinas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Create Database If Not Exists Prueb - 1

1) A database named "pruebas" is created and a table named "tblUsuarios" is created within it to store user data including ID, name, gender, level, phone, brand, company, balance, and active status. 2) The table is populated with 21 entries containing user information. 3) A number of queries are then written to select, filter, aggregate and order the user data in various ways such as by gender, brand, company, level, balance and more.

Uploaded by

Lucas Molinas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

create database if not exists pruebas;

use pruebas;

CREATE TABLE tblUsuarios (


idx INT PRIMARY KEY AUTO_INCREMENT,
usuario VARCHAR(20),
nombre VARCHAR(20),
sexo VARCHAR(1),
nivel TINYINT,
email VARCHAR(50),
telefono VARCHAR(20),
marca VARCHAR(20),
compañia VARCHAR(20),
saldo FLOAT,
activo boolean);

INSERT INTO tblUsuarios


VALUES
('1','BRE2271','BRENDA','M','2','[email protected]','655-330-
5736','SAMSUNG','IUSACELL','100','1'),
('2','OSC4677','OSCAR','H','3','[email protected]','655-143-
4181','LG','TELCEL','0','1'),
('3','JOS7086','JOSE','H','3','[email protected]','655-143-
3922','NOKIA','MOVISTAR','150','1'),
('4','LUI6115','LUIS','H','0','[email protected]','655-137-
1279','SAMSUNG','TELCEL','50','1'),
('5','LUI7072','LUIS','H','1','[email protected]','655-100-
8260','NOKIA','IUSACELL','50','0'),
('6','DAN2832','DANIEL','H','0','[email protected]','655-145-
2586','SONY','UNEFON','100','1'),
('7','JAQ5351','JAQUELINE','M','0','[email protected]','655-330-
5514','BLACKBERRY','AXEL','0','1'),
('8','ROM6520','ROMAN','H','2','[email protected]','655-330-
3263','LG','IUSACELL','50','1'),
('9','BLA9739','BLAS','H','0','[email protected]','655-330-
3871','LG','UNEFON','100','1'),
('10','JES4752','JESSICA','M','1','[email protected]','655-143-
6861','SAMSUNG','TELCEL','500','1'),
('11','DIA6570','DIANA','M','1','[email protected]','655-143-
3952','SONY','UNEFON','100','0'),
('12','RIC8283','RICARDO','H','2','[email protected]','655-145-
6049','MOTOROLA','IUSACELL','150','1'),
('13','VAL6882','VALENTINA','M','0','[email protected]','655-137-
4253','BLACKBERRY','AT&T','50','0'),
('14','BRE8106','BRENDA','M','3','[email protected]','655-100-
1351','MOTOROLA','NEXTEL','150','1'),
('15','LUC4982','LUCIA','M','3','[email protected]','655-145-
4992','BLACKBERRY','IUSACELL','0','1'),
('16','JUA2337','JUAN','H','0','[email protected]','655-100-
6517','SAMSUNG','AXEL','0','0'),
('17','ELP2984','ELPIDIO','H','1','[email protected]','655-145-
9938','MOTOROLA','MOVISTAR','500','1'),
('18','JES9640','JESSICA','M','3','[email protected]','655-330-
5143','SONY','IUSACELL','200','1'),
('19','LET4015','LETICIA','M','2','[email protected]','655-143-
4019','BLACKBERRY','UNEFON','100','1'),
('20','LUI1076','LUIS','H','3','[email protected]','655-100-
5085','SONY','UNEFON','150','1'),
('21','HUG5441','HUGO','H','2','[email protected]','655-137-
3935','MOTOROLA','AT&T','500','1');

-- Seleccionar nombre
select nombre from tblUsuarios nombres;

-- Calcular el saldo maximo de los usuarios de sexo "Mujer"


select max(saldo) from tblUsuarios where sexo="M";

-- Listar nombre,telefono de los usuarios con telefonos de la marca


NOKIA,BLACKBERRY O SONY
select nombre,telefono from tblUsuarios where marca
in("NOKIA","BLACKBERRY","SONY");

-- Contar los usuarios sin saldo o inactivos


select count(*) from tblUsuarios where saldo <=0;

-- Listar el login de los usuarios con nivel 1,2 o 3


select usuario from tblUsuarios where nivel in(1,2,3);

-- Listar los nros de telefonos con saldo menor o igual a 300


select telefono from tblUsuarios where saldo <+ 300;

-- Calcular la suma de los saldos de los usuarios de la Compañia


telefonica NEXTEL
select sum(saldo) from tblUsuarios where compañia = "NEXTEL";

-- Contar el numero de usuarios por compañia telefonica


select compañia, count(*) from tblUsuarios group by compañia;

-- Contar el nro de Usuarios por nivel


select nivel, count(*) from tblUsuarios group by nivel;

-- Listar el login de los usuarios con nivel 2


select usuario from tblUsuarios where nivel=2;

-- Mostrar el email de los usuarios que usan gmail


select email from tblUsuarios where email like "%gmail%";

-- Listar nombre y telefono de los usuarios con telefono LG,SAMSUNG O


MOTOROLA
select nombre, telefono from tblUsuarios where marca
in('LG','SAMSUNG','MOTOROLA');

-- Listar nombre y teléfono de los usuarios con teléfono que no sea de la


marca LG o SAMSUNG
select nombre,telefono,marca from tblUsuarios where marca not
in('LG','SAMSUNG');
-- Listar el login y teléfono de los usuarios con compañia telefónica
IUSACELL
select usuario,telefono,compañia from tblUsuarios where
compañia='IUSACELL';

-- Listar el login y teléfono de los usuarios con compañia telefónica que


no sea TELCEL
select usuario,telefono,compañia from tblUsuarios where
compañia!='IUSACELL';

-- Calcular el saldo promedio de los usuarios que tienen teléfono marca


NOKIA
select avg(saldo) from tblUsuarios where marca = 'NOKIA';

-- Listar el login y teléfono de los usuarios con compañia telefónica


IUSACELL o AXEL
select usuario,telefono,compañia from tblUsuarios where compañia =
'IUSACELL' or compañia = 'AXEL';

-- Mostrar el email de los usuarios que no usan yahoo


select email from tblUsuarios where email not like "%yahoo%";

-- Listar el login y teléfono de los usuarios con compañia telefónica que


no sea TELCEL o IUSACELL
select usuario,telefono,compañia from tblUsuarios where compañia not
in('TELCEL' ,'IUSACELL');

-- Listar el login y teléfono de los usuarios con compañia telefónica


UNEFON
select usuario,telefono,compañia from tblUsuarios where
compañia='UNEFON';

-- Listar las diferentes marcas de celular en orden alfabético


descendentemente
select marca from tblUsuarios order by marca desc;
select marca from tblUsuarios order by marca asc;

-- Listar las diferentes compañias en orden alfabético aleatorio


select compañia from tblUsuarios order by rand();

-- Listar el login de los usuarios con nivel 0 o 2


select usuario,nivel from tblUsuarios where nivel in(0,2);

-- Calcular el saldo promedio de los usuarios que tienen teléfono marca


LG
select avg(saldo) from tblUsuarios where marca='LG';

-- Listar el login de los usuarios con nivel 1 o 3


select usuario,nivel from tblUsuarios where nivel in(1,3);

-- Listar nombre y teléfono de los usuarios con teléfono que no sea de la


marca BLACKBERRY
select nombre,telefono from tblUsuarios where noT marca='BLACKBERRY';

-- Listar el login de los usuarios con nivel 3


select usuario,nivel from tblUsuarios where nivel = 3;

-- Listar el login de los usuarios con nivel 0


select usuario,nivel from tblUsuarios where nivel = 0;

-- Listar el login de los usuarios con nivel 1


select usuario,nivel from tblUsuarios where nivel = 1;

-- Contar el número de usuarios por sexo


select count(*), sexo from tblUsuarios group by sexo;

-- Listar el login y teléfono de los usuarios con compañia telefónica


AT&T
Select usuario,telefono from tblUsuarios where compañia = "AT&T";

-- Listar las diferentes compañias en orden alfabético descendentemente


select compañia from tblUsuarios order by compañia desc;

-- Listar el login de los usuarios inactivos


select usuario,activo from tblUsuarios where activo = false;

-- Listar los números de teléfono sin saldo


select telefono,saldo from tblUsuarios where saldo=0;

-- Calcular el saldo mínimo de los usuarios de sexo “Hombre”


select min(saldo) from tblUsuarios where sexo="H";

-- Listar los números de teléfono con saldo mayor a 300


select telefono from tblUsuarios where saldo > 300;

-- BLOQUE4
-- contar el nro de usuarios por marca de telefono
select count(*),marca from tblUsuarios group by marca;

-- listar nombre y telefono de los usuarios con telefono que no sea de la


marca LG
select nombre,telefono from tblUsuarios where not marca = 'LG';

-- listar las diferentes compañias en orden alfabetico ascendente


Select compañia from tblUsuarios order by compañia asc;

-- calcular la suma de los saldos de los usuarios de la compañia


telefonica UNEFON
select sum(saldo) from tblUsuarios where compañia = "UNEFON";

-- Mostrar email de los Usuarios que usan hotmail


select email from tblUsuarios where email like "%hotmail%";

-- listar nombre de los usuarios sin saldo o inactivos


select nombre from tblUsuarios where saldo = 0;
-- listar login y telefono de los usuarios con compañia IUSACELL O TELCEL
select telefono,compañia from tblUsuarios where compañia = 'IUSACELL' or
compañia = 'TELCEL';
-- listar las diferentes marcas de celular en orden alfabetico ascendente
select marca from tblUsuarios order by marca asc;

-- listar las diferentes marcas de celular en orden alfabetico aleatorio


select marca from tblUsuarios order by rand();

-- listar el login y telefono de los usuarios con compañia telefonica


IUSACELL o UNEFON
select usuario,telefono from tblUsuarios where compañia
IN('IUSACELL','UNEFON');

You might also like