p4_aehr

Download p4_AEHR

If you can't read please download the document

Upload: angel-hurtado

Post on 15-Nov-2015

228 views

Category:

Documents


5 download

DESCRIPTION

Practica 4 base de datos

TRANSCRIPT

ANGEL EMMANUEL HURTADO RIOS - 415120911mysql> create database llaves_AEHR;Query OK, 1 row affected (0.02 sec)mysql> use llaves_AEHRDatabase changedmysql> create table deptos(Id int not null primary key, descripcin varchar(50), num_emp smallint);Query OK, 0 rows affected (0.15 sec)mysql> create table empleados(Id int not null primary key, nombre varchar(50), ap_pat varchar(50), ap_mat varchar(50), sueldo int, fecha_ingreso date, depto int, foreign key (depto) references deptos(Id));Query OK, 0 rows affected (0.11 sec)mysql> load data infile 'e:\datos_p4dd.csv' into table deptos fields terminated by ',';Query OK, 13 rows affected (0.02 sec)Records: 13 Deleted: 0 Skipped: 0 Warnings: 0mysql> select * from deptos;+----+---------------------+---------+| Id | descripcin | num_emp |+----+---------------------+---------+| 3 | ventas | 96 || 8 | ventas | 96 || 9 | compras | 103 || 11 | sistemas | 90 || 13 | sistemas | 90 || 15 | sistemas | 90 || 25 | recursos humanos | 50 || 36 | almacen | 23 || 46 | sistemas | 90 || 49 | devoluciones | 15 || 50 | cancelaciones | 10 || 52 | limpieza | 98 || 58 | servicio al cliente | 65 |+----+---------------------+---------+13 rows in set (0.01 sec)mysql> load data infile 'e:\datos_p4de.csv' into table empleados fields terminated by ',';Query OK, 57 rows affected (0.08 sec)Records: 57 Deleted: 0 Skipped: 0 Warnings: 0mysql> select * from empleados;+-----+-----------+-----------+------------+--------+---------------+-------+| Id | nombre | ap_pat | ap_mat | sueldo | fecha_ingreso | depto |+-----+-----------+-----------+------------+--------+---------------+-------+| 100 | Ana | Alducin | Rodriguez | 3134 | 1992-10-19 | 3 || 113 | Diana | Macin | Torres | 7249 | 2000-10-10 | 36 || 118 | Ilse | Hernandez | Mosqueda | 20886 | 2007-09-09 | 46 || 124 | Ana | Alducin | Rodriguez | 3134 | 1992-10-19 | 8 || 129 | Alma | Robles | Andrade | 25656 | 2001-04-02 | 58 || 164 | Jaime | Bautista | Diaz | 7623 | 2009-12-09 | 11 || 212 | Luis | Tellez | Clairin | 5678 | 2002-05-18 | 9 || 216 | Alberto | Cortina | Bautista | 6144 | 2008-09-26 | 9 || 221 | Bernardo | Torres | Calderon | 13654 | 2011-02-10 | 50 || 226 | Sahira | Pingel | Cruz | 10956 | 2004-07-13 | 25 || 245 | Ana | Dominguez | Cortina | 2566 | 1992-12-22 | 8 || 254 | Carlos | Lopez | Sepulveda | 3228 | 2008-11-01 | 3 || 260 | Luis | Castillo | Garcia | 5270 | 1998-10-18 | 58 || 267 | Cesar | Lopez | Ortiz | 12456 | 2010-02-09 | 13 || 271 | Bianca | Gonzalez | Bustamante | 5079 | 1990-05-19 | 3 || 276 | Evelia | Salas | Quintana | 25521 | 2003-12-29 | 49 || 279 | Lorenzo | Hernandez | Martinez | 7219 | 2008-09-27 | 49 || 283 | Sonia | Rodriguez | Romero | 12478 | 1990-09-14 | 50 || 288 | Guillermo | Mejia | Hernandez | 31023 | 2004-10-16 | 36 || 296 | Luis | Castillo | Garcia | 5270 | 1998-10-18 | 58 || 300 | Roberto | Calderon | Roa | 4494 | 1996-05-10 | 46 || 301 | Gabriel | Sanchez | Osorio | 7489 | 2011-01-27 | 58 || 306 | Gisselle | Lopez | Sanchez | 33032 | 2000-02-29 | 49 || 311 | Roberto | Calderon | Roa | 4494 | 1996-05-10 | 36 || 312 | Jaime | Ruiz | Saenz | 4401 | 2003-12-07 | 52 || 313 | Juan | Olvera | Sanchez | 4638 | 2003-10-10 | 25 || 314 | Hector | Mejia | Sanchez | 5398 | 1995-08-16 | 13 || 315 | Eduardo | Galicia | Vega | 13645 | 1992-03-13 | 52 || 316 | Federico | Osorio | Castillo | 5955 | 1996-07-23 | 3 || 317 | Nestor | Munoz | Collazo | 22292 | 2006-05-29 | 36 || 318 | Noemi | Contreras | Reyna | 18920 | 2000-10-03 | 46 || 333 | Amalia | Sanchez | Arredondo | 7960 | 2001-05-01 | 25 || 342 | Maria | Alvarez | Saavedra | 20410 | 1991-07-04 | 9 || 355 | Hector | Mejia | Sanchez | 15874 | 1995-08-16 | 50 || 360 | Alma | Santiago | Hurtado | 30892 | 2002-10-06 | 52 || 362 | Eduardo | Galicia | Vega | 2710 | 1992-03-13 | 52 || 366 | Ernesto | Enciso | Castro | 7003 | 1998-06-14 | 49 || 367 | Daniela | Cruz | Regino | 16290 | 2005-03-19 | 49 || 371 | Santiago | Saavedra | Acosta | 14097 | 2000-07-23 | 36 || 420 | Irma | Martinez | Colin | 5434 | 2001-06-01 | 49 || 421 | Edwin | Falcon | Alvarado | 12820 | 2004-03-19 | 9 || 425 | Guillermo | Robles | Guzman | 23641 | 2002-05-14 | 52 || 439 | Fernanda | Clairin | Heredia | 16842 | 2010-01-22 | 3 || 452 | Amalia | Sanchez | Arredondo | 7960 | 2001-05-01 | 8 || 457 | Alberto | Cortina | Bautista | 6144 | 2008-09-26 | 9 || 478 | Ana | Dominguez | Cortina | 2566 | 1992-12-22 | 25 || 488 | Luis | Tellez | Clairin | 5678 | 2002-05-18 | 9 || 521 | Diana | Macin | Torres | 7249 | 2000-10-10 | 46 || 523 | Carlos | Lopez | Sepulveda | 3228 | 2008-11-01 | 3 || 541 | Irma | Martinez | Colin | 12456 | 2001-06-01 | 50 || 547 | Jaime | Ruiz | Saenz | 4401 | 2003-12-07 | 52 || 562 | Juan | Olvera | Sanchez | 4638 | 2003-10-10 | 8 || 566 | Rodolfo | Roa | Dominguez | 2753 | 2009-06-23 | 52 || 578 | Maria | Gonzalez | Suarez | 7967 | 2011-09-27 | 58 || 582 | Ernesto | Enciso | Castro | 7003 | 1998-06-14 | 15 || 641 | Lorenzo | Hernandez | Martinez | 7219 | 2008-09-27 | 15 || 652 | Federico | Osorio | Castillo | 5955 | 1996-07-23 | 3 |+-----+-----------+-----------+------------+--------+---------------+-------+57 rows in set (0.00 sec)mysql> show tables;+-----------------------+| Tables_in_llaves_AHER |+-----------------------+| deptos || empleados |+-----------------------+2 rows in set (0.00 sec)mysql> desc deptos;+--------------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------------+-------------+------+-----+---------+-------+| Id | int(11) | NO | PRI | NULL | || descripcin | varchar(50) | YES | | NULL | || num_emp | smallint(6) | YES | | NULL | |+--------------+-------------+------+-----+---------+-------+3 rows in set (0.02 sec)mysql> desc empleados;+---------------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+---------------+-------------+------+-----+---------+-------+| Id | int(11) | NO | PRI | NULL | || nombre | varchar(50) | YES | | NULL | || ap_pat | varchar(50) | YES | | NULL | || ap_mat | varchar(50) | YES | | NULL | || sueldo | int(11) | YES | | NULL | || fecha_ingreso | date | YES | | NULL | || depto | int(11) | YES | MUL | NULL | |+---------------+-------------+------+-----+---------+-------+7 rows in set (0.03 sec)mysql> select descripcin,count(*) as num_reg from deptos group by descripcin;+---------------------+---------+| descripcin | num_reg |+---------------------+---------+| almacen | 1 || cancelaciones | 1 || compras | 1 || devoluciones | 1 || limpieza | 1 || recursos humanos | 1 || servicio al cliente | 1 || sistemas | 4 || ventas | 2 |+---------------------+---------+9 rows in set (0.00 sec)mysql> select max(id) as id_mayor from deptos where descripcin in('sistemas','ventas') group by id;+----------+| id_mayor |+----------+| 3 || 8 || 11 || 13 || 15 || 46 |+----------+6 rows in set (0.00 sec)mysql> select descripcin,max(id) as id_mayor from deptos where descripcin in('sistemas','ventas') group by descripcin;+--------------+----------+| descripcin | id_mayor |+--------------+----------+| sistemas | 46 || ventas | 8 |+--------------+----------+2 rows in set (0.02 sec)mysql> select descripcin,id from deptos where descripcin in('sistemas','ventas');+--------------+----+| descripcin | id |+--------------+----+| ventas | 3 || ventas | 8 || sistemas | 11 || sistemas | 13 || sistemas | 15 || sistemas | 46 |+--------------+----+6 rows in set (0.01 sec)mysql> update empleados set depto=46 where depto in(11,13,15);Query OK, 5 rows affected (0.01 sec)Rows matched: 5 Changed: 5 Warnings: 0mysql> mysql> update empleados set depto=8 where depto in(3);Query OK, 7 rows affected (0.01 sec)Rows matched: 7 Changed: 7 Warnings: 0mysql> mysql> delete from deptos where id in(3,11,13,15);Query OK, 4 rows affected (0.00 sec)mysql> alter table empleados add edad tinyint after fecha_ingreso;Query OK, 0 rows affected (0.19 sec)Records: 0 Duplicates: 0 Warnings: 0mysql> update empleados set edad=33 where id update empleados set edad=35 where (id between 200 and 299) and fecha_ingreso>'2000-01-01';Query OK, 9 rows affected (0.02 sec)Rows matched: 9 Changed: 9 Warnings: 0mysql> update empleados set edad=40 where (id between 200 and 299) and fecha_ingreso update empleados set edad=36 where (id between 300 and 499);Query OK, 27 rows affected (0.00 sec)Rows matched: 27 Changed: 27 Warnings: 0mysql> update empleados set edad=42 where id>=400 and fecha_ingreso update empleados set edad=37 where id>=400 and fecha_ingreso>'2000-01-01';Query OK, 15 rows affected (0.01 sec)Rows matched: 15 Changed: 15 Warnings: 0mysql> select edad,count(*) as num_registros from empleados group by edad order by edad desc;+------+---------------+| edad | num_registros |+------+---------------+| 42 | 3 || 40 | 5 || 37 | 15 || 36 | 19 || 35 | 9 || 33 | 6 |+------+---------------+6 rows in set (0.02 sec)mysql> mysql> select nombre,ap_pat,ap_mat from empleados where depto=8;+----------+-----------+------------+| nombre | ap_pat | ap_mat |+----------+-----------+------------+| Ana | Alducin | Rodriguez || Ana | Alducin | Rodriguez || Ana | Dominguez | Cortina || Carlos | Lopez | Sepulveda || Bianca | Gonzalez | Bustamante || Federico | Osorio | Castillo || Fernanda | Clairin | Heredia || Amalia | Sanchez | Arredondo || Carlos | Lopez | Sepulveda || Juan | Olvera | Sanchez || Federico | Osorio | Castillo |+----------+-----------+------------+11 rows in set (0.00 sec)mysql> select e.nombre,e.ap_pat,e.ap_mat,e.fecha_ingreso,d.descripcin from empleados e, deptos d where fecha_ingreso between '2004-01-01' and '2008-01-01' group by e.id;+-----------+-----------+-----------+---------------+--------------+| nombre | ap_pat | ap_mat | fecha_ingreso | descripcin |+-----------+-----------+-----------+---------------+--------------+| Ilse | Hernandez | Mosqueda | 2007-09-09 | ventas || Sahira | Pingel | Cruz | 2004-07-13 | ventas || Guillermo | Mejia | Hernandez | 2004-10-16 | ventas || Nestor | Munoz | Collazo | 2006-05-29 | ventas || Daniela | Cruz | Regino | 2005-03-19 | ventas || Edwin | Falcon | Alvarado | 2004-03-19 | ventas |+-----------+-----------+-----------+---------------+--------------+6 rows in set (0.02 sec)mysql> select * from empleados e, deptos d where d.descripcin like '%s' and d.descripcin like '%e%' and d.descripcin not like '%e%e%' and e.sueldo>5000 and e.fecha_ingreso between '2009-01-01' and '2009-12-31' group by e.id;+-----+--------+----------+--------+--------+---------------+------+-------+----+--------------+---------+| Id | nombre | ap_pat | ap_mat | sueldo | fecha_ingreso | edad | depto | Id | descripcin | num_emp |+-----+--------+----------+--------+--------+---------------+------+-------+----+--------------+---------+| 164 | Jaime | Bautista | Diaz | 7623 | 2009-12-09 | 33 | 46 | 8 | ventas | 96 |+-----+--------+----------+--------+--------+---------------+------+-------+----+--------------+---------+1 row in set (0.00 sec)mysql> exit