Sunteți pe pagina 1din 34

Laboratorio​ ​14

CRISTIAN​​OSWALDO​​PARRA​​VARGAS

SERVICIO​ ​NACIONAL​ ​DE​ ​APRENDIZAJE​ ​SENA MODALIDAD​ ​VIRTUAL

ANALISIS​ ​Y​ ​DESARROLLO​ ​DE​ ​SISTEMAS​ ​DE​ ​INFORMACION​ ​ADSI

2017

Laboratorio​ ​12

1.​ ​Crear​ ​las​ ​tablas​ ​propuestas​ ​en​ ​el​ ​ejercicio

Creamos​ ​la​ ​base​ ​de​ ​datos​ ​y​ ​utilizamos​ ​“use​ ​para​ ​trabajar​ ​con​ ​ella:

mysql>​ ​create​ ​database​ ​laboratorioSQL; Query​ ​OK,​ ​1​ ​row​ ​affected​ ​(0.03​ ​sec)

mysql>​ ​use​ ​laboratorioSQL; Database​ ​changed

Creamos​ ​las​ ​tablas:

mysql>​ ​create​ ​table​ ​Profesor(doc_prof​ ​varchar(11)​ ​primary​ ​key​ ​not​ ​null,​ ​nom_prof​ ​varchar(30) not​ ​null,​ ​ape_profesor​ ​varchar(30)​ ​not​ ​null,​ ​cate_prof​ ​int,​ ​sal_prof​ ​int);

Con​ ​“describe”​ ​podemos​ ​ver​ ​cómo​ ​quedó​ ​la​ ​tabla​ ​que​ ​hicimos:

mysql>​ ​describe​ ​profesor;

 +- --- +--------- +----- +------- --- +---------------- ------ ---- +----- -- - + | |​ ​Field |​ ​Type Null |​ ​Key​ ​|​ ​Default​ ​|​ ​Extra​ ​| +- --- +-------- +----- +------- --- +----------------- ------ ---- +----- -- - + | varchar |​ ​doc profesor (11) |​ ​NO |​ ​PRI​ ​|​ ​NULL | | | |​ ​nom profesor​ ​|​ ​varchar(30)​ ​|​ ​NO | NULL | | | varchar( | |​ ​ape profesor 30) |​ ​NO | NULL | | | YE | |​ ​cate prof |​ ​int(11) S | NULL | | | YE | |​ ​sal prof |​ ​int(11) S | NULL | | +- +--------- +----- +------- --- +---------------- ------ ---- +------ --- - +

5​ ​rows​ ​in​ ​set​ ​(0.16​ ​sec)

mysql>​ ​create​ ​table​ ​curso(cod_curso​ ​int​ ​primary​ ​key​ ​auto_increment​ ​not​ ​null,​ ​nom_curs varchar(100)​ ​not​ ​null,horas_cur​ ​int,​ ​valor_cur​ ​int);

mysql>​ ​create​ ​table​ ​Estudiante(doc_est​ ​varchar(11)​ ​primary​ ​key​ ​not​ ​null,​ ​nom_est​ ​varchar(30) not​ ​null,​ ​ape_est​ ​varchar(30)​ ​not​ ​null,​ ​edad_est​ ​int);

La​ ​tabla​ ​Estudianxcurso​ ​la​ ​creamos​ ​pero​ ​no​ ​designamos​ ​las​ ​claves​ ​foráneas:

mysql>​ ​create​ ​table​ ​Estudiantexcurso(cod_curso_estcur​ ​int​ ​not​ ​null,​ ​doc_est_estcur​ ​varchar(11) not​ ​null,​ ​fec_ini_estcur​ ​date);

Designamos​ ​las​ ​fk​ ​individualmente:

mysql>​ ​alter​ ​table​ ​estudiantexcurso​ ​add​ ​constraint​ ​fkdoc_est​ ​foreign​ ​key(doc_est_estcur) references​ ​estudiante(doc_est);

mysql>​ ​alter​ ​table​ ​estudiantexcurso​ ​add​ ​constraint​ ​fkcodcurs​ ​foreign​ ​key(cod_curso_estcur) references​ ​curso(cod_curso);

mysql>​​create​​table​​Cliente(id_cli​​varchar(11)​​primary​​key​​not​​null,​​nom_cli​​varchar(30)​​not​​null,

ape_cli​​varchar(30)​​not​​null,​​dir_cli​​varchar(100),​​dep_cli​​varchar(20),​​mes_cum_cli​​varchar(10));

mysql>​ ​create​ ​table​ ​Articulo(id_art​ ​int​ ​primary​ ​key​ ​not​ ​null​ ​auto_increment,​ ​tit_art​ ​varchar(100), aut_art​ ​varchar(100),​ ​edi_art​ ​varchar(300),​ ​prec_art​ ​int​ ​not​ ​null);

Creamos​ ​la​ ​tabla​ ​Pedido​ ​y​ ​luego​ ​referenciamos​ ​id_cli_ped​ ​como​ ​foránea:

mysql>​ ​create​ ​table​ ​Pedido(id_pedido​ ​int​ ​primary​ ​key​ ​not​ ​null​ ​auto_increment,​ ​id_cli_ped varchar(11),​ ​fec_ped​ ​date​ ​not​ ​null,​ ​val_ped​ ​int​ ​not​ ​null);

mysql>​ ​alter​ ​table​ ​pedido​ ​add​ ​constraint​ ​fkid_cli​ ​foreign​ ​key(id_cli_ped)​ ​references Cliente(id_cli);

mysql>​ ​create​ ​table​ ​Articuloxpedido(id_ped_artped​ ​int​ ​not​ ​null,​ ​id_art_artped​ ​int,​ ​can_art_artped int,​ ​val_ven_art_artped​ ​int);

mysql>​ ​alter​ ​table​ ​Articuloxpedido​ ​add​ ​constraint​ ​fk_id_ped​ ​foreign​ ​key(id_ped_artped) references​ ​Pedido(id_pedido);

mysql>​ ​alter​ ​table​ ​Articuloxpedido​ ​add​ ​constraint​ ​fk_art_ped​ ​foreign​ ​key(id_art_artped) references​ ​Articulo(id_art);

mysql>​ ​create​ ​table​ ​Compañia(comnit​ ​varchar(11)​ ​primary​ ​key​ ​not​ ​null,​ ​comnombre​ ​varchar(30) not​ ​null,​ ​comañofun​ ​int,​ ​comreplegal​ ​varchar(100));

mysql>​ ​create​ ​table​ ​TiposAutomotores(autotipo​ ​int​ ​primary​ ​key​ ​not​ ​null);

mysql>​ ​create​ ​table​ ​Automotores(autoplaca​ ​varchar(6)​ ​primary​ ​key​ ​not​ ​null,​ ​automarca varchar(30)​ ​not​ ​null,​ ​autotipo​ ​int,​ ​automodelo​ ​int,​ ​autonumpasajeros​ ​int,​ ​autocilindraje​ ​int, autonumchasis​ ​varchar(20));

mysql>​ ​alter​ ​table​ ​Automotores​ ​add​ ​constraint​ ​fk_tipoauto​ ​foreign​ ​key(Autotipo)​ ​references TiposAutomotores(autotipo);

Aquí​ ​me​ ​dio​ ​un​ ​error​ ​de​ ​sintaxis​ ​y​ ​no​ ​lograba​ ​encontrar​ ​el​ ​por​ ​qué:

mysql>​ ​create​ ​table​ ​aseguramientos(asecodigo​ ​int(6)​ ​primary​ ​key​ ​not​ ​null​ ​auto_increment, asefechainicio​ ​datenot​ ​null,​ ​asefechainspiracion​ ​date​ ​not​ ​null,​ ​asevalorasegurado​ ​int​ ​not​ ​null, aseestado​ ​varchar​ ​not​ ​null,​ ​asecosto​ ​int​ ​not​ ​null,​ ​aseplaca​ ​varchar(6)); ERROR​ ​1064​ ​(42000):​ ​You​ ​have​ ​an​ ​error​ ​in​ ​your​ ​SQL​ ​syntax;​ ​check​ ​the​ ​manual​ ​that corresponds​ ​to​ ​your​ ​MySQL​ ​server​ ​version​ ​for​ ​the​ ​right​ ​syntax​ ​to​ ​use​ ​near​ ​'date​ ​not​ ​null, asefechainspiracion​ ​date​ ​not​ ​null,​ ​asevalorasegurado​ ​int​ ​not​ ​null,'​ ​at​ ​line​ ​1

Como​ ​fallé​ ​varias​ ​veces​ ​al​ ​intentar​ ​crear​ ​la​ ​tabla​ ​decidí​ ​crearla​ ​sólo​ ​con​ ​su​ ​tabla primaria​ ​para​ ​ir​ ​añadiendo​ ​columnas​ ​hasta​ ​hallar​ ​el​ ​error:

mysql>​ ​create​ ​table​ ​aseguramientos(asecodigo​ ​int(6)​ ​primary​ ​key​ ​not​ ​null​ ​auto_increment); mysql>​ ​alter​ ​table​ ​aseguramientos​ ​add​ ​asefechainicio​ ​date​ ​not​ ​null​ ​after​ ​asecodigo; mysql>​ ​alter​ ​table​ ​aseguramientos​ ​add​ ​asefechaexpiracion​ ​date​ ​not​ ​null​ ​after​ ​asefechainicio; mysql>​ ​alter​ ​table​ ​aseguramientos​ ​add​ ​asevalorasegurado​ ​int​ ​not​ ​null​ ​after​ ​asefechaexpiracion;

El​ ​problema​ ​era​ ​que​ ​“aseestado”​ ​no​ ​tenía​ ​longitud​ ​en​ ​el​ ​ejercicio​ ​y​ ​hay​ ​varchar​ ​hay que​ ​asignarle​ ​una:

mysql>​ ​alter​ ​table​ ​aseguramientos​ ​add​ ​constraint​ ​fk_placas​ ​foreign​ ​key(aseplaca)​ ​references automotores(autoplaca);

Y​ ​ahora​ ​​ ​quedó​ ​bien​ ​la​ ​tabla:

mysql>​ ​describe​ ​automotores;

 + - - - - - - - - - - - - +- - +------ --- +--------------------- - + ------+--------- --- --- + | T y p |​ ​Field e |​ ​Null​ ​|​ ​Key |​ ​Default​ ​|​ ​Extra​ ​| + - - - - - - - - - - - - - +- - +------ --- +--------------------- - +------+-----​ ​-- --- --- + | v | a NUL |​ ​autoplaca r |​ ​NO |​ ​PRI L | |
 c h a r ( 6 ) | |​ ​varchar(30)​ ​| NUL |​ ​automarca NO | L | | | |​ ​autotipo |​ ​YES |​ ​MUL​ ​| NULL | | | | NUL |​ ​automodelo |​ ​YES | L | | | NUL |​ ​autonumpasajeros​ ​|​ ​int(11) |​ ​YES | L | | | | NUL |​ ​autocilindraje |​ ​YES | L | | | | varch NUL |​ ​autonumchasis ar(20) |​ ​YES​ ​| L | | +------- +- -------- +------ --- +--------------------- - +------ +------- --- --- +

7​ ​rows​ ​in​ ​set​ ​(0.00​ ​sec)

mysql>​ ​create​ ​table​ ​incidentes(incicodigo​ ​int​ ​primary​ ​key​ ​not​ ​null​ ​auto_increment,​ ​incifecha date​ ​not​ ​null,​ ​inciplaca​ ​varchar(6)​ ​not​ ​null,​ ​incilugar​ ​varchar(40)​ ​not​ ​null,​ ​incicantheridos​ ​int, incicantfatalidades​ ​int,​ ​incicanautosinvolucrados​ ​int);

mysql>​ ​alter​ ​table​ ​incidentes​ ​add​ ​constraint​ ​fk_inciplacas​ ​foreign​ ​key(inciplaca)​ ​references automotores(autoplaca);

mysql>​​insert​​into​​profesor​​values('63.502.720',​​'Martha',​​'Rojas',​​2,​​690000);

mysql>​​insert​​into​​profesor​​values('91.216.904',​​'Carlos',​​'Pérez',​​3,​​950000);

mysql>​​insert​​into​​profesor​​values('13.826.789',​​'Maritza',​​'Angarita',​​1,​​550000);

Con​ ​este​ ​obtuvimos​ ​error​ ​por​ ​la​ ​longitud:

mysql>​ ​insert​ ​into​ ​profesor​ ​values('1.098.765.789',​ ​'Alejandra',​ ​'Torres',​ ​4,​ ​1100000);​ ​ERROR 1406​ ​(22001):​ ​Data​ ​too​ ​long​ ​for​ ​column​ ​'doc_profesor'​ ​at​ ​row​ ​1

Se​ ​cambia​ ​la​ ​longitud​ ​de​ ​doc_profesor:

mysql>​ ​alter​ ​table​ ​profesor​ ​modify​ ​doc_profesor​ ​varchar(20); mysql>​ ​insert​ ​into​ ​profesor​ ​values('1.098.765.789',​ ​'Alejandra',​ ​'Torres',​ ​4,​ ​1100000); mysql>​ ​select​ ​*​ ​from​ ​profesor;

+---------------

|​ ​doc profesor

+-----------------

|​ ​1.098.765.789

|​ ​13.826.789

|​ ​63.502.720

|​ ​91.216.904

+-----------------

+---

----

----

---- +---------- +------------------- -

-

+

|​ ​nom_profesor​ ​|​ ​ape_profesor​ ​|​ ​cate_prof​ ​|​ ​sal_prof

+----------

 | +--- ---- ---- +--------- ---- +---------- -------- - - +---------- + | | Alejandr Tor a res | 4​ ​| 1100000​ ​| | An gari |​ ​Maritza ta | 1​ ​| 550000​ ​| | Roj |​ ​Martha as | 2​ ​| 690000​ ​| | Pér |​ ​Carlos ez | 3​ ​| 950000​ ​| +--- ---- ---- +--------- ---- +---------- -------- - - +---------- +

mysql>​ ​insert​ ​into​ ​curso​ ​values ->​ ​(149842,​ ​'Fundamentos​ ​de​ ​bases​ ​de​ ​datos',​ ​40,​ ​500000),​ ​->​ ​(250067,'Fundamentos​ ​de​ ​SQL', 20,​ ​700000),​ ​->​ ​(289011,​ ​'Manejo​ ​de​ ​MYSQL',​ ​45,​ ​550000), ->​ ​(345671,​ ​'Fundamentals​ ​of​ ​Oracle',60,​ ​3000000);

mysql>​ ​insert​ ​into​ ​estudiante​ ​values ->​ ​('63.502.720',​ ​'María',​ ​'Perez',​ ​23), ->​ ​('91.245.678',​ ​'Carlos​ ​Jose',​ ​'Lopez',​ ​25), ->​ ​('1.098.098.097',​ ​'Jonatan',​ ​'Ardila',​ ​17), ->​ ​('1.098.765.768',​ ​'Carlos',​ ​'Martinez',​ ​19);

mysql>​ ​insert​ ​into​ ​curso​ ​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);

mysql>​ ​insert​ ​into​ ​estudiantexcurso​ ​values ->​ ​(289011,​ ​'1.098.765.678',​ ​'2011-01-02'), ->​ ​(250067,​ ​'63.502.720',​ ​'2011-01-03'), ->​ ​(289011,​ ​'1.098.098.097',​ ​'2011-01-02'), ->​ ​(345671,​ ​'63.502.720',​ ​'2011-01-04');

mysql>​ ​insert​ ​into​ ​cliente​ ​values

->​​('63502718',​​'Maritza',​​'Rojas',​​'Calle​​34​​No.​​14-45',​​'Santander',​​'Abril'),​​->

('13890234',​​'Roger',​​'Ariza',​​'Carrera​​30​​No.​​13-45',​​'Antioquia',​​'Junio'),

->​​('77191956',​​'Juan​​Carlos',​​'Arenas',​​'Diagonal​​23​​No.​​12-34​​apto.​​101',​​'Valle',​​'Marzo'),​​->

mysql>​ ​insert​ ​into​ ​articulo​ ​values ->​ ​(Null,'Redes​ ​cisco',​ ​'Ernesto​ ​Arigasello',​ ​'Alfaomega-Rama',​ ​60000), ->​ ​(Null,​ ​'Facebook​ ​y​ ​twitter​ ​para​ ​adultos',​ ​'Veloso​ ​Claudio',​ ​'Alfaomega-Rama',​ ​52000), ->​ ​(Null,​ ​'Creación​ ​de​ ​un​ ​portal​ ​con​ ​php​ ​y​ ​mysql',​ ​'Jacobo​ ​Pavón​ ​Puertas',​ ​'Alfaomega-Rama',

40000),

->​ ​(Null,​ ​'Administración​ ​de​ ​sistemas​ ​operativos',​ ​'Julio​ ​Gómez​ ​López',​ ​'Alfaomega-Rama',

55000);

mysql>​ ​insert​ ​into​ ​pedido​ ​values ->​ ​(null,'63502718','2012-02-25',120000), ->​ ​(null,'77191956','2012-04-30',55000), ->​ ​(null,'63502718','2011-12-10',260000), ->​ ​(null,'1098765789','2012-02-25',1800000);

mysql>​ ​insert​ ​into​ ​articuloxpedido​ ​values ->​ ​(1,​ ​3,​ ​5,​ ​40000), ->​ ​(1,​ ​4,​ ​12,​ ​55000), ->​ ​(2,​ ​1,​ ​5,​ ​65000), ->​ ​(3,​ ​2,​ ​10,​ ​55000), ->​ ​(3,​ ​3,​ ​12,​ ​45000), ->​ ​(4,​ ​1,​ ​20,​ ​65000);

mysql>​ ​insert​ ​into​ ​compañia​ ​values ->​ ​('800890890-2',​ ​'Seguros​ ​Atlantida',​ ​1998,​ ​'Carlos​ ​López'), ->​ ​('899999999-1',​ ​'Aseguradora​ ​Rojas',​ ​1991,​ ​'Luis​ ​Fernando​ ​Rojas'), ->​ ​('899999999-5',​ ​'Seguros​ ​del​ ​Estadio',​ ​2001,​ ​'Maria​ ​Margarita​ ​Pérez');

La​ ​tabla​ ​TiposAutomotores​ ​no​ ​tenía​ ​columna​ ​autnombre:

mysql>​ ​alter​ ​table​ ​tiposautomotores​ ​add​ ​column​ ​(autnombre​ ​varchar(11)​ ​not​ ​null);​ ​Query​ ​OK,​ ​0 rows​ ​affected​ ​(0.72​ ​sec)

mysql>​ ​insert​ ​into​ ​tiposautomotores​ ​values ->​ ​(1,​ ​'Automóviles'), ->​ ​(2,​ ​'Camperos'), ->​ ​(3,​ ​'Camiones');

mysql>​ ​insert​ ​into​ ​automotores​ ​values

->​​('FLL420',​​'Chevrolet​​corsa',​​1,​​2003,​​5,​​1400,​​'wywzzz167kk009d25'),​​->

('DKZ820',​​'Renault​​stepway',​​1,​​2008,​​5,​​1600,​​'wywzzz157kk009d45'),​​->

('KJQ920',​​'Kia​​sportage',​​2,​​2009,​​7,​​2000,​​'wywzzz157kk009d25');

mysql>​ ​insert​ ​into​ ​aseguramientos​ ​values

-> (1, '2012-09-30', '2013-09-30', 30000000, 'Vigente', 'FLL420', 500000), -> (2, '2012-09-27', '2013-09-27', 35000000, 'Vigente', 'DKZ820', 600000), ->

(3,​​'2011-09-28',​​'2012-09-28',​​50000000,​​'Vencido',​​'KJQ920',​​800000);

mysql>​ ​insert​ ​into​ ​incidentes​ ​values ->​ ​(1,​ ​'2012-09-30',​ ​'DKZ820',​ ​'Bucaramanga',​ ​0,​ ​0,​ ​2),​ ​->​ ​(2,​ ​'2012-09-27',​ ​'FLL420',​ ​'Girón', 1,​ ​0,​ ​1), ->​ ​(3,​ ​'2011-09-28',​ ​'FLL420',​ ​'Bucaramanga',​ ​1,​ ​0,​ ​2);​ ​Query​ ​OK,​ ​3​ ​rows​ ​affected​ ​(0.19​ ​sec)

3.​ ​Realizamos​ ​consultas

Salarios​ ​de​ ​los​ ​profesores​ ​ordenados​ ​por​ ​categorías:

mysql>​ ​select​ ​sal_prof​ ​from​ ​profesor​ ​order​ ​by​ ​cate_prof;

+--------

+

|​ ​sal prof​ ​|

+--------

+

| 550000​ ​|

| 690000​ ​|

| 950000​ ​|

| 1100000​ ​|

+

+--------

--

--

--

Mostrar​ ​cursos​ ​con​ ​valor​ ​mayor​ ​a​ ​\$500000:

mysql>​ ​select​ ​valor_cur​ ​from​ ​curso​ ​where​ ​valor_cur​ ​>​ ​500000; +-----------+ |​ ​valor_cur​ ​|

+---------

+

| 700000​ ​|

| 550000​ ​|

| 3000000​ ​|

+

+---------

--

--

Número​ ​de​ ​estudiantes​ ​cuya​ ​edad​ ​sea​ ​mayor​ ​a​ ​22​ ​años:

mysql>​ ​select​ ​count(*)​ ​from​ ​estudiante​ ​where​ ​edad_est​ ​>​ ​22; +----------+ |​ ​count(*)​ ​|

 +------- --- + | 2​ ​|

+-------

+ 1​ ​row​ ​in​ ​set​ ​(0.05​ ​sec)

---

Muestrar​ ​nombre​ ​y​ ​edad​ ​del​ ​estudiante​ ​más​ ​joven:

|

+----------+ 1​ ​row​ ​in​ ​set​ ​(0.00​ ​sec)

17

|

Calcular​​el​​valor​​promedio​​de​​lso​​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.00​ ​sec)

Sueldo​ ​promedio​ ​de​ ​los​ ​profesores​ ​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)

Mostrar​ ​todos​ ​los​ ​campos​ ​de​ ​la​ ​tabla​ ​curso​ ​en​ ​orden​ ​ascendente​ ​por​ ​valor:

mysql>​ ​select​ ​*​ ​from​ ​curso​ ​order​ ​by​ ​valor cur​ ​asc;

+------

--------

--------

-------- +----------

 +----------- -------- - +------------- + |​ ​cod curso​ ​|​ ​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)

Mostrar​ ​nombre​ ​del​ ​profesor​ ​con​ ​menos​ ​sueldo:

mysql>​ ​select​ ​nom_profesor​ ​from​ ​profesor​ ​order​ ​by​ ​sal_prof​ ​asc​ ​limit​ ​1; +-----------------+ |​ ​nom_profesor​ ​| +-----------------+

|​ ​Maritza

+-----------------+ 1​ ​row​ ​in​ ​set​ ​(0.00​ ​sec)

|

Mostrar​ ​estudiantes​ ​(código​ ​y​ ​nombre)​ ​que​ ​iniciaron​ ​curso​ ​el​ ​01-02-2011,​ ​del​ ​curso debe​ ​mostrarse​ ​el​ ​nombre,​ ​las​ ​horas​ ​y​ ​el​ ​valor:

mysql>​ ​select​ ​doc_est,​ ​nom_est,​ ​fec_ini_estcur,​ ​nom_curs,​ ​horas_cur,​ ​valor_cur​ ​->​ ​from estudiante​ ​join​ ​estudiantexcurso​ ​join​ ​curso ->​ ​on​ ​fec_ini_estcur​ ​=​ ​'2011-01-02'and​ ​doc_est​ ​=​ ​doc_est_estcur​ ​and​ ​cod_curso_estcur​ ​= cod curso;

 +---------- +------- +-----------------+-----------+-----------------+------------------------ - ---- +

|​ ​doc est

+-----------------+-----------

|​ ​1.098.765.678​ ​|​ ​Carlos

|​ ​nom est​ ​|​ ​fec ini estcur​ ​|​ ​nom curs |​ ​horas cur​ ​|​ ​valor cur​ ​|

+----------------- +-----------------------

+ | 550000​ ​|

+--------- --+-------

----

45

-

-

|​ ​2011-01-02 |​ ​Manejo​ ​de​ ​MySQL​ ​|

|​ ​1.098.098.097​ ​|​ ​Jonatan

45

+----------- +----------------------- +----------

|​ ​2011-01-02 |​ ​Manejo​ ​de​ ​MySQL​ ​​ ​|

| 550000​ ​|

 +------- +----------------- -+----------------- -- - ---- +

2​ ​rows​ ​in​ ​set​ ​(0.01​ ​sec)

Visualizar​ ​profesores​ ​cuyo​ ​sueldo​ ​esté​ ​entre​ ​\$500000​ ​y​ ​\$700000:

mysql>​ ​select​ ​nom_profesor,​ ​ape_profesor,​ ​sal_prof​ ​->​ ​from​ ​profesor ->​ ​where​ ​sal_prof​ ​>=​ ​500000​ ​and​ ​sal_prof​ ​<=​ ​700000;

Mostrar​​nombre,​​apellido​​y​​dirección​​de​​los​​clientes​​que​​realizaron​​pedido​​el​​día​​25/02/2012:

mysql>​ ​select​ ​nom_cli,​ ​ape_cli,​ ​fec_ped ->​ ​from​ ​cliente​ ​join​ ​pedido ->​ ​on​ ​id_cli_ped​ ​=​ ​id_cli​ ​and​ ​fec_ped​ ​=​ ​'2012-02-25';

 +--------- - +---------+------------ + |​ ​nom cli |​ ​ape cli​ ​|​ ​fec ped | +--------- - |​ ​Maritza +---------+------------ + |​ ​Rojas|​ ​2012-02-25​ ​|

|​ ​Catalina​ ​|​ ​Zapata |​ ​2012-02-25​ ​|

 +--------- - +---------+------------ +

2​ ​rows​ ​in​ ​set​ ​(0.00​ ​sec)

Lista​ ​de​ ​todos​ ​los​ ​pedidos​ ​con​ ​el​ ​nombre​ ​del​ ​artículo:

mysql>​ ​select​ ​fec_ped,​ ​tit_art,​ ​nom_cli,​ ​can_art_artped ->​ ​from​ ​articulo​ ​join​ ​articuloxpedido​ ​join​ ​pedido​ ​join​ ​cliente

->​ ​on​ ​id_cli_ped​ ​=​ ​id_cli​ ​and​ ​id_ped_artped​ ​=​ ​id_pedido​ ​and​ ​id_art​ ​=​ ​id_art_artped; ------------------------------------------------- +------------ +---------------

 +------------+ - - - + |​ ​fec ped |​ ​tit art |​ ​nom cli |​ ​can art artped​ ​|

------------------------------------------------- +------------ +---------------

 +------------+ - - - + |​ ​2012-02-25 |​ ​Creación​ ​de​ ​un​ ​portal​ ​con​ ​php​ ​y​ ​mysql |​ ​Maritza | 5​ ​|

|​ ​2012-02-25 |​ ​Administración​ ​de​ ​sistemas​ ​operativos |​ ​Maritza

|​ ​2012-04-30 |​ ​Redes​ ​cisco |​ ​2011-12-10​ ​|​ ​Facebook​ ​y​ ​twitter​ ​para​ ​adultos |​ ​2011-12-10​ ​|​ ​Creación​ ​de​ ​un​ ​portal​ ​con​ ​php​ ​y​ ​mysql |​ ​2012-02-25 |​ ​Redes​ ​cisco

|​ ​Juan​ ​Carlos​ ​| |​ ​Maritza |​ ​Maritza |​ ​Catalina

|

| 12​ ​| 5​ ​| 10​ ​| | 12​ ​| | 20​ ​|

------------------------------------------------- +------------ +---------------

--

+------------+ 6​ ​rows​ ​in​ ​set​ ​(0.00​ ​sec)

-

--

+

Visualizar​ ​los​ ​clientes​ ​que​ ​cumplen​ ​años​ ​en​ ​marzo:

mysql>​ ​select​ ​nom_cli,​ ​mes_cum_cli ->​ ​from​ ​cliente ->​ ​where​ ​mes_cum_cli​ ​=​ ​'Marzo';

 +------------ - +----------------+ |​ ​nom cli |​ ​mes cum cli​ ​| +------------ - +----------------+ |​ ​Catalina |​ ​Marzo |

|​ ​Juan​ ​Carlos​ ​|​ ​Marzo

|

 +------------ -- +---------------+

2​ ​rows​ ​in​ ​set​ ​(0.00​ ​sec)

Visualizar​​los​​datos​​del​​pedido​​1​​incluyendo​​el​​nombre​​del​​cliente,​​la​​dirección​​del​​mismo​​y​​el

mysql>​ ​select​ ​id_ped_artped,​ ​nom_cli,​ ​dir_cli,​ ​tit_art,​ ​prec_art,​ ​can_art_artped,​ ​val_ped​ ​->​ ​from articuloxpedido​ ​join​ ​cliente​ ​join​ ​articulo​ ​join​ ​pedido ->​ ​on​ ​id_cli​ ​=​ ​id_cli_ped​ ​and​ ​id_pedido​ ​=​ ​id_ped_artped​ ​and​ ​id_ped_artped​ ​=​ ​1​ ​and​ ​id_art= id_art_artped;

Visualizar​ ​cliente,​ ​fecha​ ​y​ ​valor​ ​del​ ​pedido​ ​más​ ​costoso:

mysql>​ ​select​ ​nom_cli,​ ​fec_ped,val_ped ->​ ​from​ ​cliente​ ​join​ ​pedido

->​ ​on​ ​id_cli​ ​=​ ​id_cli_ped​ ​order​ ​by​ ​val_ped​ ​desc​ ​limit​ ​1;

 +--------- - +---------------+-----------+ |​ ​nom cli |​ ​fec ped |​ ​val ped | +--------- - +---------------+-----------+

|​ ​Catalina​ ​|​ ​2012-02-25 |​ ​1800000​ ​|

 +--------- - +---------------+-----------+

1​ ​row​ ​in​ ​set​ ​(0.00​ ​sec)

Ver​ ​el​ ​conteo​ ​de​ ​artículos​ ​por​ ​editorial​ ​(sólo​ ​hay​ ​una​ ​editorial):

mysql>​ ​select​ ​count(*)​ ​as​ ​id_art ->​ ​from​ ​articulo ->​ ​group​ ​by​ ​edi_art; +--------+

|​ ​id

+--------+

|

+--------+

art

|

|

​​ ​4

​​

Mostrar​ ​todos​ ​los​ ​pedidos​ ​con​ ​los​ ​respectivos​ ​articulos:

mysql>​ ​select​ ​id art artped,​ ​tit art,​ ​can art artped,​ ​val ven art artped

->​ ​from

articuloxp

edido​ ​join

articulo

join

pedido

->​ ​on

id_pedido

=

id_ped_art

ped​ ​and

id_art​ ​=

id_art_artp

ed;

 + - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +--------------- - - -+
 - - - - - - - - - - - - - | ca n_ art _ar tpe d​​| val _v en _ar t_a rtp ed |​ ​id art artped​ ​|​ ​tit art | + + - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - -