Solucion Laboratorio SQL

Descargar como txt, pdf o txt
Descargar como txt, pdf o txt
Está en la página 1de 16

Ejercicios:

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)

mysql> create database laboratorioSQL;


Query OK, 1 row affected (0.01 sec)

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| laboratoriosql |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

2. Ubicado en la base de datos que acab� de crear, construya las siguientes tablas
con los respectivos campos y tipos de datos.

mysql> use laboratoriosql;


Database changed
mysql> Create Table Profesor (
-> Doc_Prof Varchar(11) Not Null ,
-> Nom_Prof Varchar(30) Not Null,
-> Ape_Prof Varchar(30) Not Null,
-> Cate_Prof Int Not Null,
-> Sal_Prof Int Not Null,
-> Primary Key (Doc_Prof));
Query OK, 0 rows affected (0.66 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Curso (
-> Cod_Curs Varchar(6) Not Null ,
-> Nom_Curs Varchar(100) Not Null,
-> Horas_Cur Int Not Null,
-> Valor_Cur Int Not Null,
-> Primary Key (Cod_Curs));
Query OK, 0 rows affected (0.23 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Estudiante (
-> Doc_Est Varchar(11) Not Null ,
-> Nom_Est Varchar(30) Not Null,
-> Ape_Est Varchar(30) Not Null,
-> Edad_Est Int Not Null,
-> Primary Key (Doc_Est));
Query OK, 0 rows affected (0.16 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Estudiantexcurso (
-> Cod_Cur_Estcur Varchar(6) Not Null ,
-> Doc_Est_Estcur Varchar(11) Not Null,
-> Fec_Ini_Estcur Date Not Null,
-> Foreign Key (Cod_Cur_Estcur) References Curso(Cod_Curs),
-> Foreign Key (Doc_Est_Estcur) References Estudiante(Doc_Est));
Query OK, 0 rows affected (0.28 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Cliente (
-> Id_Cli Varchar(11) Not Null,
-> Nom_Cli Varchar(30) Not Null,
-> Ape_Cli Varchar(30) Not Null,
-> Dir_Cli Varchar(100) Not Null,
-> Dep_Cli Varchar(20) Not Null,
-> Mes_Cum_Cli Varchar(10) Not Null,
-> Primary Key (Id_Cli));
Query OK, 0 rows affected (0.19 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Articulo (
-> Id_Art Int Not Null Auto_Increment,
-> Tit_Art Varchar(100) Not Null,
-> Aut_Art Varchar(100) Not Null,
-> Edi_Art Varchar(300) Not Null,
-> Prec_Art Int Not Null,
-> Primary Key (Id_Art));
Query OK, 0 rows affected (0.20 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Pedido (
-> Id_Ped Int Not Null Auto_Increment,
-> Id_Cli_Ped Varchar(11) Not Null,
-> Fec_Ped Date Not Null,
-> Val_Ped Int Not Null,
-> Primary Key (Id_Ped),
-> Foreign Key (Id_Cli_Ped) References Cliente(Id_Cli));
Query OK, 0 rows affected (0.18 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Articuloxpedido (
-> Id_Ped_Artped Int Not Null,
-> Id_Art_Artped Int Not Null,
-> Can_Art_Artped Int Not Null,
-> Val_Ven_Art_Artped Int Not Null,
-> Foreign Key (Id_Ped_Artped) References Pedido(Id_Ped),
-> Foreign Key (Id_Art_Artped) References Articulo(Id_Art));
Query OK, 0 rows affected (0.21 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Compania (
-> Comnit Varchar(11) Not Null,
-> Comnombre Varchar(30) Not Null,
-> Comanofun Int Not Null,
-> Comreplegal Varchar(100) Not Null,
-> Primary Key (Comnit));
Query OK, 0 rows affected (0.17 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Tiposautomotores (
-> Auttipo Int Not Null Auto_Increment,
-> Autnombre Varchar(30) Not Null,
-> Primary Key (Auttipo));
Query OK, 0 rows affected (0.19 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Automotores (
-> Autoplaca Varchar(6) Not Null,
-> Automarca Varchar(30) Not Null,
-> Autotipo Int Not Null,
-> Automodelo Int Not Null,
-> Autonumpasajeros Int Not Null,
-> Autocilindraje Int Not Null,
-> Autonumchasis Varchar(20),
-> Primary Key (Autoplaca),
-> Foreign Key (Autotipo) References Tiposautomotores(Auttipo));
Query OK, 0 rows affected (0.14 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Aseguramientos (
-> Asecodigo Int Not Null Auto_Increment,
-> Asefechainicio Date Not Null,
-> Asefechaexpiracion Date Not Null,
-> Asevalorasegurado Int Not Null,
-> Aseestado Varchar(10) Not Null,
-> Asecosto Int Not Null,
-> Aseplaca Varchar(6) Not Null,
-> Primary Key (Asecodigo),
-> Foreign Key (Aseplaca) References Automotores(Autoplaca));
Query OK, 0 rows affected (0.22 sec)

mysql> use laboratoriosql;


Database changed
mysql> Create Table Incidentes (
-> Incicodigo Int Not Null Auto_Increment,
-> Incifecha Date Not Null,
-> Inciplaca Varchar(6) Not Null,
-> Incilugar Varchar(40) Not Null,
-> Incicantheridos Int Not Null,
-> Incicanfatalidades Int Not Null,
-> Incicanautosinvolucrados Int Not Null,
-> Primary Key (Incicodigo),
-> Foreign Key (Inciplaca) References Automotores(Autoplaca));
Query OK, 0 rows affected (0.18 sec)
mysql> show tables from laboratoriosql;
+--------------------------+
| Tables_in_laboratoriosql |
+--------------------------+
| articulo |
| articuloxpedido |
| aseguramientos |
| automotores |
| cliente |
| compania |
| curso |
| estudiante |
| estudiantexcurso |
| incidentes |
| pedido |
| profesor |
| tiposautomotores |
+--------------------------+
13 rows in set (0.00 sec)

3. Inserte los siguientes registros seg�n las tablas que se presentan a


continuaci�n:

mysql> use laboratoriosql;


Database changed
mysql> describe Profesor;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Doc_Prof | varchar(11) | NO | PRI | NULL | |
| Nom_Prof | varchar(30) | NO | | NULL | |
| Ape_Prof | varchar(30) | NO | | NULL | |
| Cate_Prof | int(11) | NO | | NULL | |
| Sal_Prof | int(11) | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.20 sec)

mysql> Insert Into `Profesor` (`Doc_Prof`, `Nom_Prof`, `Ape_Prof`, `Cate_Prof`,


`Sal_Prof`) Values
-> ('1098765789', 'Alejandra', 'Torres', 4, 1100000),
-> ('13826789', 'Maritza', 'Angarita', 1, 550000),
-> ('63502720', 'Martha', 'Rojas', 2, 690000),
-> ('91216904', 'Carlos', 'Perez', 3, 950000);
Query OK, 4 rows affected (0.26 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from Profesor;


+------------+-----------+----------+-----------+----------+
| Doc_Prof | Nom_Prof | Ape_Prof | Cate_Prof | Sal_Prof |
+------------+-----------+----------+-----------+----------+
| 1098765789 | Alejandra | Torres | 4 | 1100000 |
| 13826789 | Maritza | Angarita | 1 | 550000 |
| 63502720 | Martha | Rojas | 2 | 690000 |
| 91216904 | Carlos | Perez | 3 | 950000 |
+------------+-----------+----------+-----------+----------+
4 rows in set (0.02 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Curso;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| Cod_Curs | varchar(6) | NO | PRI | NULL | |
| Nom_Curs | varchar(100) | NO | | NULL | |
| Horas_Cur | int(11) | NO | | NULL | |
| Valor_Cur | int(11) | NO | | NULL | |
+-----------+--------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> Insert Into `Curso` (`Cod_Curs`, `Nom_Curs`, `Horas_Cur`, `Valor_Cur`)


Values
-> ('149842', 'Fundamentos De Bases De Datos', 40, 500000),
-> ('250067', 'Fundamentos De Sql', 20, 700000),
-> ('289011', 'Manejo De Mysql', 45, 550000),
-> ('345671', 'Fundamentos De Oracle', 60, 3000000);
Query OK, 4 rows affected (0.08 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from Curso;


+----------+-------------------------------+-----------+-----------+
| Cod_Curs | Nom_Curs | Horas_Cur | Valor_Cur |
+----------+-------------------------------+-----------+-----------+
| 149842 | Fundamentos De Bases De Datos | 40 | 500000 |
| 250067 | Fundamentos De Sql | 20 | 700000 |
| 289011 | Manejo De Mysql | 45 | 550000 |
| 345671 | Fundamentos De Oracle | 60 | 3000000 |
+----------+-------------------------------+-----------+-----------+
4 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Estudiante;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Doc_Est | varchar(11) | NO | PRI | NULL | |
| Nom_Est | varchar(30) | NO | | NULL | |
| Ape_Est | varchar(30) | NO | | NULL | |
| Edad_Est | int(11) | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.02 sec)

mysql> Insert Into `Estudiante` (`Doc_Est`, `Nom_Est`, `Ape_Est`, `Edad_Est`)


Values
-> ('1098098097', 'Jonatan', 'Ardila', 17),
-> ('1098765678', 'Carlos', 'Martinez', 19),
-> ('63502720', 'Maria', 'Perez', 23),
-> ('91245678', 'Carlos Jos�', 'Lopez', 25);
Query OK, 4 rows affected (0.07 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from Estudiante;


+------------+--------------+----------+----------+
| Doc_Est | Nom_Est | Ape_Est | Edad_Est |
+------------+--------------+----------+----------+
| 1098098097 | Jonatan | Ardila | 17 |
| 1098765678 | Carlos | Martinez | 19 |
| 63502720 | Maria | Perez | 23 |
| 91245678 | Carlos Jos� | Lopez | 25 |
+------------+--------------+----------+----------+
4 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Estudiantexcurso;
+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| Cod_Cur_Estcur | varchar(6) | NO | MUL | NULL | |
| Doc_Est_Estcur | varchar(11) | NO | MUL | NULL | |
| Fec_Ini_Estcur | date | NO | | NULL | |
+----------------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> Insert Into `Estudiantexcurso` (`Cod_Cur_Estcur`, `Doc_Est_Estcur`,


`Fec_Ini_Estcur`) Values
-> ('289011', '1098765678', '2011-02-01'),
-> ('250067', '63502720', '2011-03-01'),
-> ('289011', '1098098097', '2011-02-01'),
-> ('345671', '63502720', '2011-04-01');
Query OK, 4 rows affected (0.09 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from Estudiantexcurso;


+----------------+----------------+----------------+
| Cod_Cur_Estcur | Doc_Est_Estcur | Fec_Ini_Estcur |
+----------------+----------------+----------------+
| 289011 | 1098765678 | 2011-02-01 |
| 250067 | 63502720 | 2011-03-01 |
| 289011 | 1098098097 | 2011-02-01 |
| 345671 | 63502720 | 2011-04-01 |
+----------------+----------------+----------------+
4 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Cliente;
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| Id_Cli | varchar(11) | NO | PRI | NULL | |
| Nom_Cli | varchar(30) | NO | | NULL | |
| Ape_Cli | varchar(30) | NO | | NULL | |
| Dir_Cli | varchar(100) | NO | | NULL | |
| Dep_Cli | varchar(20) | NO | | NULL | |
| Mes_Cum_Cli | varchar(10) | NO | | NULL | |
+-------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> Insert Into `Cliente` (`Id_Cli`, `Nom_Cli`, `Ape_Cli`, `Dir_Cli`, `Dep_Cli`,
`Mes_Cum_Cli`) Values
-> ('1098765789', 'Catalina', 'Zapata', 'Av El Libertador 30-14', 'Cauca',
'Marzo'),
-> ('13890234', 'Roger', 'Ariza', 'Cra 30 No. 13-45', 'Antioquia', 'Junio'),
-> ('63502718', 'Maritza', 'Rojas', 'Calle 34 No. 14-45', 'Santander',
'Abril'),
-> ('77191956', 'Juan Carlos', 'Arenas', 'Digonal 23 No. 12-34 Apto 101',
'Valle', 'Marzo');
Query OK, 4 rows affected (0.05 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from Cliente;


+------------+-------------+---------+-------------------------------+-----------
+-------------+
| Id_Cli | Nom_Cli | Ape_Cli | Dir_Cli | Dep_Cli |
Mes_Cum_Cli |
+------------+-------------+---------+-------------------------------+-----------
+-------------+
| 1098765789 | Catalina | Zapata | Av El Libertador 30-14 | Cauca |
Marzo |
| 13890234 | Roger | Ariza | Cra 30 No. 13-45 | Antioquia |
Junio |
| 63502718 | Maritza | Rojas | Calle 34 No. 14-45 | Santander |
Abril |
| 77191956 | Juan Carlos | Arenas | Digonal 23 No. 12-34 Apto 101 | Valle |
Marzo |
+------------+-------------+---------+-------------------------------+-----------
+-------------+
4 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Articulo;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| Id_Art | int(11) | NO | PRI | NULL | auto_increment |
| Tit_Art | varchar(100) | NO | | NULL | |
| Aut_Art | varchar(100) | NO | | NULL | |
| Edi_Art | varchar(300) | NO | | NULL | |
| Prec_Art | int(11) | NO | | NULL | |
+----------+--------------+------+-----+---------+----------------+
5 rows in set (0.03 sec)

mysql> Insert Into `Articulo` (`Id_Art`, `Tit_Art`, `Aut_Art`, `Edi_Art`,


`Prec_Art`) Values
-> (1, 'Redes Cisco', 'Ernesto Arigasello', 'Alfaomega-Rama', 60000),
-> (2, 'Facebook Y Twitter Para Adultos', 'Veloso Claudio', 'Alfaomega',
52000),
-> (3, 'Creaci�n De Una Portal Con Php Y Mysql', 'Jacobo Pab�n Puertas', 'Alfa-
Omega Rama', 40000),
-> (4, 'Administraci�n De Sistemas Operativos', 'Julio Gomez Lopez', 'Alfaomega
- Rama', 55000);
Query OK, 4 rows affected (0.03 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from Articulo;


+--------+-----------------------------------------+-----------------------
+------------------+----------+
| Id_Art | Tit_Art | Aut_Art |
Edi_Art | Prec_Art |
+--------+-----------------------------------------+-----------------------
+------------------+----------+
| 1 | Redes Cisco | Ernesto Arigasello |
Alfaomega-Rama | 60000 |
| 2 | Facebook Y Twitter Para Adultos | Veloso Claudio |
Alfaomega | 52000 |
| 3 | Creaci�n De Una Portal Con Php Y Mysql | Jacobo Pab�n Puertas | Alfa-
Omega Rama | 40000 |
| 4 | Administraci�n De Sistemas Operativos | Julio Gomez Lopez |
Alfaomega - Rama | 55000 |
+--------+-----------------------------------------+-----------------------
+------------------+----------+
4 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Pedido;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| Id_Ped | int(11) | NO | PRI | NULL | auto_increment |
| Id_Cli_Ped | varchar(11) | NO | MUL | NULL | |
| Fec_Ped | date | NO | | NULL | |
| Val_Ped | int(11) | NO | | NULL | |
+------------+-------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)

mysql> Insert Into `Pedido` (`Id_Ped`, `Id_Cli_Ped`, `Fec_Ped`, `Val_Ped`) Values


-> (1, '63502718', '2012-02-25', 120000),
-> (2, '77191956', '2012-04-30', 55000),
-> (3, '63502718', '2011-12-10', 260000),
-> (4, '1098765789', '2012-02-25', 1800000);
Query OK, 4 rows affected (0.04 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from Pedido;


+--------+------------+------------+---------+
| Id_Ped | Id_Cli_Ped | Fec_Ped | Val_Ped |
+--------+------------+------------+---------+
| 1 | 63502718 | 2012-02-25 | 120000 |
| 2 | 77191956 | 2012-04-30 | 55000 |
| 3 | 63502718 | 2011-12-10 | 260000 |
| 4 | 1098765789 | 2012-02-25 | 1800000 |
+--------+------------+------------+---------+
4 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Articuloxpedido;
+--------------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+---------+------+-----+---------+-------+
| Id_Ped_Artped | int(11) | NO | MUL | NULL | |
| Id_Art_Artped | int(11) | NO | MUL | NULL | |
| Can_Art_Artped | int(11) | NO | | NULL | |
| Val_Ven_Art_Artped | int(11) | NO | | NULL | |
+--------------------+---------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> Insert Into `Articuloxpedido` (`Id_Ped_Artped`, `Id_Art_Artped`,


`Can_Art_Artped`, `Val_Ven_Art_Artped`) Values
-> (1, 3, 5, 40000),
-> (1, 4, 12, 50000),
-> (2, 1, 5, 65000),
-> (3, 2, 10, 55000),
-> (3, 3, 12, 45000),
-> (4, 1, 20, 65000);
Query OK, 6 rows affected (0.07 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> select * from Articuloxpedido;


+---------------+---------------+----------------+--------------------+
| Id_Ped_Artped | Id_Art_Artped | Can_Art_Artped | Val_Ven_Art_Artped |
+---------------+---------------+----------------+--------------------+
| 1 | 3 | 5 | 40000 |
| 1 | 4 | 12 | 50000 |
| 2 | 1 | 5 | 65000 |
| 3 | 2 | 10 | 55000 |
| 3 | 3 | 12 | 45000 |
| 4 | 1 | 20 | 65000 |
+---------------+---------------+----------------+--------------------+
6 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Compania;
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| Comnit | varchar(11) | NO | PRI | NULL | |
| Comnombre | varchar(30) | NO | | NULL | |
| Comanofun | int(11) | NO | | NULL | |
| Comreplegal | varchar(100) | NO | | NULL | |
+-------------+--------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> Insert Into `Compania` (`Comnit`, `Comnombre`, `Comanofun`, `Comreplegal`)


Values
-> ('8008908902', 'Seguros Atlantida', 1998, 'Carlos L�pez'),
-> ('8999999991', 'Aseguradora Rojas', 1991, 'Luis Fernando Rojas'),
-> ('8999999995', 'Seguros Del Estado', 2001, 'Maria Margarita Perez');
Query OK, 3 rows affected (0.04 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from Compania;


+------------+--------------------+-----------+-----------------------+
| Comnit | Comnombre | Comanofun | Comreplegal |
+------------+--------------------+-----------+-----------------------+
| 8008908902 | Seguros Atlantida | 1998 | Carlos L�pez |
| 8999999991 | Aseguradora Rojas | 1991 | Luis Fernando Rojas |
| 8999999995 | Seguros Del Estado | 2001 | Maria Margarita Perez |
+------------+--------------------+-----------+-----------------------+
3 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Tiposautomotores;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| Auttipo | int(11) | NO | PRI | NULL | auto_increment |
| Autnombre | varchar(30) | NO | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

mysql> Insert Into `Tiposautomotores` (`Auttipo`, `Autnombre`) Values


-> (1, 'Automoviles'),
-> (2, 'Camperos'),
-> (3, 'Camiones');
Query OK, 3 rows affected (0.06 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from Tiposautomotores;


+---------+-------------+
| Auttipo | Autnombre |
+---------+-------------+
| 1 | Automoviles |
| 2 | Camperos |
| 3 | Camiones |
+---------+-------------+
3 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Automotores;
+------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-------------+------+-----+---------+-------+
| Autoplaca | varchar(6) | NO | PRI | NULL | |
| Automarca | varchar(30) | NO | | NULL | |
| Autotipo | int(11) | NO | MUL | NULL | |
| Automodelo | int(11) | NO | | NULL | |
| Autonumpasajeros | int(11) | NO | | NULL | |
| Autocilindraje | int(11) | NO | | NULL | |
| Autonumchasis | varchar(20) | YES | | NULL | |
+------------------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)

mysql> Insert Into `Automotores` (`Autoplaca`, `Automarca`, `Autotipo`,


`Automodelo`, `Autonumpasajeros`, `Autocilindraje`, `Autonumchasis`) Values
-> ('Dkz820', 'Renault Stepway', 1, 2008, 5, 1600, 'Wywzzz157kk009d45'),
-> ('Fll420', 'Chevrolet Corsa', 1, 2003, 5, 1400, 'Wywzzz167kk009d25'),
-> ('Kjq920', 'Kia Sportage', 2, 2009, 7, 2000, 'Wywzzz157kk009d25');
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from Automotores;


+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+
| Autoplaca | Automarca | Autotipo | Automodelo | Autonumpasajeros |
Autocilindraje | Autonumchasis |
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+
| Dkz820 | Renault Stepway | 1 | 2008 | 5 |
1600 | Wywzzz157kk009d45 |
| Fll420 | Chevrolet Corsa | 1 | 2003 | 5 |
1400 | Wywzzz167kk009d25 |
| Kjq920 | Kia Sportage | 2 | 2009 | 7 |
2000 | Wywzzz157kk009d25 |
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+
3 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Aseguramientos;
+--------------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+-------------+------+-----+---------+----------------+
| Asecodigo | int(11) | NO | PRI | NULL | auto_increment |
| Asefechainicio | date | NO | | NULL | |
| Asefechaexpiracion | date | NO | | NULL | |
| Asevalorasegurado | int(11) | NO | | NULL | |
| Aseestado | varchar(10) | NO | | NULL | |
| Asecosto | int(11) | NO | | NULL | |
| Aseplaca | varchar(6) | NO | MUL | NULL | |
+--------------------+-------------+------+-----+---------+----------------+
7 rows in set (0.01 sec)

mysql> Insert Into `Aseguramientos` (`Asecodigo`, `Aseplaca`, `Asefechainicio`,


`Asefechaexpiracion`, `Asevalorasegurado`, `Aseestado`, `Asecosto`) Values
-> (1, 'Fll420', '2012-09-30', '2013-09-30', 30000000, 'Vigente', 500000),
-> (2, 'Dkz820', '2012-09-27', '2013-09-27', 35000000, 'Vigente', 600000),
-> (3, 'Kjq920', '2011-09-28', '2012-09-28', 50000000, 'Vencido', 800000);
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from Aseguramientos;


+-----------+----------------+--------------------+-------------------+-----------
+----------+----------+
| Asecodigo | Asefechainicio | Asefechaexpiracion | Asevalorasegurado | Aseestado |
Asecosto | Aseplaca |
+-----------+----------------+--------------------+-------------------+-----------
+----------+----------+
| 1 | 2012-09-30 | 2013-09-30 | 30000000 | Vigente |
500000 | Fll420 |
| 2 | 2012-09-27 | 2013-09-27 | 35000000 | Vigente |
600000 | Dkz820 |
| 3 | 2011-09-28 | 2012-09-28 | 50000000 | Vencido |
800000 | Kjq920 |
+-----------+----------------+--------------------+-------------------+-----------
+----------+----------+
3 rows in set (0.00 sec)

mysql> use laboratoriosql;


Database changed
mysql> describe Incidentes;
+--------------------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------------+-------------+------+-----+---------+----------------+
| Incicodigo | int(11) | NO | PRI | NULL | auto_increment |
| Incifecha | date | NO | | NULL | |
| Inciplaca | varchar(6) | NO | MUL | NULL | |
| Incilugar | varchar(40) | NO | | NULL | |
| Incicantheridos | int(11) | NO | | NULL | |
| Incicanfatalidades | int(11) | NO | | NULL | |
| Incicanautosinvolucrados | int(11) | NO | | NULL | |
+--------------------------+-------------+------+-----+---------+----------------+
7 rows in set (0.01 sec)

mysql> Insert Into `Incidentes` (`Incicodigo`, `Incifecha`, `Inciplaca`,


`Incilugar`, `Incicantheridos`, `Incicanfatalidades`, `Incicanautosinvolucrados`)
Values
-> (1, '2012-09-30', 'Dkz820', 'Bucaramanga', 0, 0, 2),
-> (2, '2012-09-27', 'Fll420', 'Giron', 1, 0, 1),
-> (3, '2011-09-28', 'Fll420', 'Bucaramanga', 1, 0, 2);
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from Incidentes;


+------------+------------+-----------+-------------+-----------------
+--------------------+--------------------------+
| Incicodigo | Incifecha | Inciplaca | Incilugar | Incicantheridos |
Incicanfatalidades | Incicanautosinvolucrados |
+------------+------------+-----------+-------------+-----------------
+--------------------+--------------------------+
| 1 | 2012-09-30 | Dkz820 | Bucaramanga | 0 |
0 | 2 |
| 2 | 2012-09-27 | Fll420 | Giron | 1 |
0 | 1 |
| 3 | 2011-09-28 | Fll420 | Bucaramanga | 1 |
0 | 2 |
+------------+------------+-----------+-------------+-----------------
+--------------------+--------------------------+
3 rows in set (0.00 sec)

4. Realice las siguientes consultas:

� Muestre los salarios de los profesores ordenados por categor�a

mysql> select Cate_Prof, Sal_Prof from Profesor order by Cate_Prof ASC;


+-----------+----------+
| Cate_Prof | Sal_Prof |
+-----------+----------+
| 1 | 550000 |
| 2 | 690000 |
| 3 | 950000 |
| 4 | 1100000 |
+-----------+----------+
4 rows in set (0.04 sec)

� Muestre los cursos cuyo valor sea mayor a $500.000.

mysql> Select * From Curso Where Valor_Cur> "$500.000";


+----------+-------------------------------+-----------+-----------+
| Cod_Curs | Nom_Curs | Horas_Cur | Valor_Cur |
+----------+-------------------------------+-----------+-----------+
| 149842 | Fundamentos De Bases De Datos | 40 | 500000 |
| 250067 | Fundamentos De Sql | 20 | 700000 |
| 289011 | Manejo De Mysql | 45 | 550000 |
| 345671 | Fundamentos De Oracle | 60 | 3000000 |
+----------+-------------------------------+-----------+-----------+
4 rows in set, 1 warning (0.05 sec)

� Cuente el n�mero de estudiantes cuya edad sea mayor a 22.

mysql> Select Nom_Est,Max(Edad_Est) From Estudiante;


+---------+---------------+
| Nom_Est | Max(Edad_Est) |
+---------+---------------+
| Jonatan | 25 |
+---------+---------------+
1 row in set (0.04 sec)

� Muestre el nombre y la edad del estudiante m�s joven.

mysql> Select Nom_Est,Min(Edad_Est) From Estudiante;


+---------+---------------+
| Nom_Est | Min(Edad_Est) |
+---------+---------------+
| Jonatan | 17 |
+---------+---------------+
1 row in set (0.00 sec)

� Calcule el valor promedio de los cursos cuyas horas sean mayores a 40.

mysql> Select Avg(Valor_Cur) From Curso Where Horas_Cur>40;


+----------------+
| Avg(Valor_Cur) |
+----------------+
| 1775000.0000 |
+----------------+
1 row in set (0.02 sec)

� Obtener el sueldo promedio de los profesores de la categor�a 1.

mysql> Select Avg(Sal_Prof) From Profesor Where Cate_Prof=1;


+---------------+
| Avg(Sal_Prof) |
+---------------+
| 550000.0000 |
+---------------+
1 row in set (0.02 sec)

� Muestre todos los campos de la tabla curso en orden ascendente seg�n el valor.

mysql> Select * From Curso Order By Valor_Cur;


+----------+-------------------------------+-----------+-----------+
| Cod_Curs | Nom_Curs | Horas_Cur | Valor_Cur |
+----------+-------------------------------+-----------+-----------+
| 149842 | Fundamentos De Bases De Datos | 40 | 500000 |
| 289011 | Manejo De Mysql | 45 | 550000 |
| 250067 | Fundamentos De Sql | 20 | 700000 |
| 345671 | Fundamentos De Oracle | 60 | 3000000 |
+----------+-------------------------------+-----------+-----------+
4 rows in set (0.00 sec)

� Muestre el nombre del profesor con menor sueldo.

mysql> Select Nom_Prof,Ape_Prof,Min(Sal_Prof) From Profesor;


+-----------+----------+---------------+
| Nom_Prof | Ape_Prof | Min(Sal_Prof) |
+-----------+----------+---------------+
| Alejandra | Torres | 550000 |
+-----------+----------+---------------+
1 row in set (0.00 sec)
� Visualizar todos los estudiantes (c�digo y nombre) que iniciaron cursos el
01/02/2011, del curso debe mostrarse el nombre, las horas y el valor.

mysql> SELECT C.NOM_CURS,C.HORAS_CUR,E.NOM_EST,E.APE_EST


-> FROM
-> CURSO C,ESTUDIANTE E,ESTUDIANTEXCURSO EXC
-> WHERE EXC.COD_CUR_ESTCUR=C.COD_CURS AND EXC.DOC_EST_ESTCUR=E.DOC_EST
-> AND EXC.FEC_INI_ESTCUR='2011-02-01';
+-----------------+-----------+---------+----------+
| NOM_CURS | HORAS_CUR | NOM_EST | APE_EST |
+-----------------+-----------+---------+----------+
| Manejo De Mysql | 45 | Carlos | Martinez |
| Manejo De Mysql | 45 | Jonatan | Ardila |
+-----------------+-----------+---------+----------+
2 rows in set (0.02 sec)

� Visualice los profesores cuyo sueldo este entre $500.000 y $700.000.

mysql> SELECT * FROM PROFESOR WHERE SAL_PROF>=500000 AND SAL_PROF <=700000;


+----------+----------+----------+-----------+----------+
| Doc_Prof | Nom_Prof | Ape_Prof | Cate_Prof | Sal_Prof |
+----------+----------+----------+-----------+----------+
| 13826789 | Maritza | Angarita | 1 | 550000 |
| 63502720 | Martha | Rojas | 2 | 690000 |
+----------+----------+----------+-----------+----------+
2 rows in set (0.00 sec)

� Listar todos los pedidos realizados incluyendo el nombre del articulo.

mysql> Select A.Tit_Art,P.* From Pedido P,Articulo A,Articuloxpedido Axp Where


A.Id_Art=Axp.Id_Art_Artped And P.Id_Ped=Axp.Id_Ped_Artped;
+-----------------------------------------+--------+------------+------------
+---------+
| Tit_Art | Id_Ped | Id_Cli_Ped | Fec_Ped |
Val_Ped |
+-----------------------------------------+--------+------------+------------
+---------+
| Redes Cisco | 2 | 77191956 | 2012-04-30 |
55000 |
| Redes Cisco | 4 | 1098765789 | 2012-02-25 |
1800000 |
| Facebook Y Twitter Para Adultos | 3 | 63502718 | 2011-12-10 |
260000 |
| Creaci�n De Una Portal Con Php Y Mysql | 1 | 63502718 | 2012-02-25 |
120000 |
| Creaci�n De Una Portal Con Php Y Mysql | 3 | 63502718 | 2011-12-10 |
260000 |
| Administraci�n De Sistemas Operativos | 1 | 63502718 | 2012-02-25 |
120000 |
+-----------------------------------------+--------+------------+------------
+---------+
6 rows in set (0.02 sec)

. Visualizar los clientes que cumplen a�os en marzo.

mysql> Select * From Cliente Where Mes_Cum_Cli='Marzo';


+------------+-------------+---------+-------------------------------+---------
+-------------+
| Id_Cli | Nom_Cli | Ape_Cli | Dir_Cli | Dep_Cli |
Mes_Cum_Cli |
+------------+-------------+---------+-------------------------------+---------
+-------------+
| 1098765789 | Catalina | Zapata | Av El Libertador 30-14 | Cauca |
Marzo |
| 77191956 | Juan Carlos | Arenas | Digonal 23 No. 12-34 Apto 101 | Valle |
Marzo |
+------------+-------------+---------+-------------------------------+---------
+-------------+
2 rows in set (0.00 sec)

� Visualizar los datos del pedido 1, incluyendo el nombre del cliente, la direcci�n
del mismo, el nombre y el valor de los art�culos que tiene dicho pedido.

mysql> SELECT C.NOM_CLI,C.DIR_CLI,C.NOM_CLI,A.PREC_ART FROM CLIENTE C,PEDIDO


P,ARTICULOXPEDIDO AXP,ARTICULO A WHERE C.ID_CLI=P.ID_CLI_PED AND
P.ID_PED=AXP.ID_PED_ARTPED AND AXP.ID_ART_ARTPED=A.ID_ART AND P.ID_PED=1;
+---------+--------------------+---------+----------+
| NOM_CLI | DIR_CLI | NOM_CLI | PREC_ART |
+---------+--------------------+---------+----------+
| Maritza | Calle 34 No. 14-45 | Maritza | 40000 |
| Maritza | Calle 34 No. 14-45 | Maritza | 55000 |
+---------+--------------------+---------+----------+
2 rows in set (0.00 sec)

� Visualizar los datos de la p�liza cuyo valor asegurado es el m�s costoso, este
reporte adem�s de visualizar todos los datos de la p�liza, debe presentar todos los
datos del veh�culo que tiene dicha p�liza.

mysql> SELECT ASEGURAMIENTOS.*,AUTOMOTORES.* FROM AUTOMOTORES,ASEGURAMIENTOS WHERE


AUTOMOTORES.AUTOPLACA=ASEGURAMIENTOS.ASEPLACA AND AUTOMOTORES.AUTOTIPO=1;
+-----------+----------------+--------------------+-------------------+-----------
+----------+----------+-----------+-----------------+----------+------------
+------------------+----------------+-------------------+
| Asecodigo | Asefechainicio | Asefechaexpiracion | Asevalorasegurado | Aseestado |
Asecosto | Aseplaca | Autoplaca | Automarca | Autotipo | Automodelo |
Autonumpasajeros | Autocilindraje | Autonumchasis |
+-----------+----------------+--------------------+-------------------+-----------
+----------+----------+-----------+-----------------+----------+------------
+------------------+----------------+-------------------+
| 1 | 2012-09-30 | 2013-09-30 | 30000000 | Vigente |
500000 | Fll420 | Fll420 | Chevrolet Corsa | 1 | 2003 |
5 | 1400 | Wywzzz167kk009d25 |
| 2 | 2012-09-27 | 2013-09-27 | 35000000 | Vigente |
600000 | Dkz820 | Dkz820 | Renault Stepway | 1 | 2008 |
5 | 1600 | Wywzzz157kk009d45 |
+-----------+----------------+--------------------+-------------------+-----------
+----------+----------+-----------+-----------------+----------+------------
+------------------+----------------+-------------------+
2 rows in set (0.00 sec)

� Visualizar los datos de las p�lizas de los automotores tipo 1, este reporte debe
incluir placa, marca, modelo, cilindraje del veh�culo junto con la fecha de inicio,
de finalizaci�n y estado de la p�liza.

mysql> SELECT C.NOM_CLI,C.DIR_CLI,C.NOM_CLI,A.PREC_ART FROM CLIENTE C,PEDIDO


P,ARTICULOXPEDIDO AXP,ARTICULO A WHERE C.ID_CLI=P.ID_CLI_PED AND
P.ID_PED=AXP.ID_PED_ARTPED AND AXP.ID_ART_ARTPED=A.ID_ART AND P.ID_PED=1;
+---------+--------------------+---------+----------+
| NOM_CLI | DIR_CLI | NOM_CLI | PREC_ART |
+---------+--------------------+---------+----------+
| Maritza | Calle 34 No. 14-45 | Maritza | 40000 |
| Maritza | Calle 34 No. 14-45 | Maritza | 55000 |
+---------+--------------------+---------+----------+
2 rows in set (0.00 sec)

También podría gustarte