mysql> alter table libro change titulo descripcion char(30)not null; Query OK, 0 rows affected (0.17 sec) Records: 0 Duplicates: 0 Warnings: 0 //Listar mysql> select * from libro; +---------+---------------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+---------------------+-----------+--------+-----------+ | L01 | Calculo ll | 120 | 55000 | M01 | | L02 | BD ll | 150 | 65000 | M09 | | L03 | Estructura de datos | 180 | 85000 | M03 | | L04 | Ingles | 280 | 105000 | M04 | | L05 | Admon en una pagina | 70 | 7500 | M05 | | L06 | Contabilidad | 170 | 25700 | M06 | | L07 | Redes | 370 | 32500 | M07 | | L08 | Diagramacion | 85 | 45000 | M08 | +---------+---------------------+-----------+--------+-----------+ 8 rows in set (0.00 sec) mysql> select * from autor; +----------+----------------------+ | cadautor | nombre | +----------+----------------------+ | A01 | Luis Joyanes | | A02 | Jorge Vasquez Posada | | A03 | Jhon Soars | | A04 | Riaz Khadem | | A05 | Robert Lorber | | A06 | Mario Dream | +----------+----------------------+ 6 rows in set (0.00 sec) mysql> select * from editorial; +---------+--------------+ | codedit | nombre | +---------+--------------+ | E01 | Oveja Negra | | E02 | Norma | | E03 | Mc Graw Hill | +---------+--------------+ 3 rows in set (0.00 sec) mysql> select * from materia; +-----------+---------------------+ | codigomat | nombre | +-----------+---------------------+ | M01 | Calculo | | M02 | Matematicas | | M03 | Estructura de datos | | M04 | Ingl | | M05 | Sistemas de Inf | | M06 | Contabilidad | | M07 | Redes | | M08 | Diagramacion | | M09 | Base de Datos | +-----------+---------------------+ 9 rows in set (0.00 sec) mysql> select idlibro, precio from libro; +---------+--------+ | idlibro | precio | +---------+--------+ | L01 | 55000 | | L02 | 65000 | | L03 | 85000 | | L04 | 105000 | | L05 | 7500 | | L06 | 25700 | | L07 | 32500 | | L08 | 45000 | +---------+--------+ 8 rows in set (0.00 sec) mysql> alter table materia rename to asignatura; Query OK, 0 rows affected (0.52 sec) mysql> show tables; +--------------------+ | Tables_in_libreria | +--------------------+ | asignatura | | autor | | editorial | | liautedi | | libro | +--------------------+ 5 rows in set (0.00 sec) Funciones Precio mysql> select sum(precio)from libro; +-------------+ | sum(precio) | +-------------+ | 420700 | +-------------+ 1 row in set (0.00 sec) mysql> select max(precio) from libro; +-------------+ | max(precio) | +-------------+ | 105000 | +-------------+ 1 row in set (0.00 sec) mysql> select avg(precio) from libro; +-------------+ | avg(precio) | +-------------+ | 52587.5000 | +-------------+ 1 row in set (0.00 sec) mysql> select precio from libro; +--------+ | precio | +--------+ | 55000 | | 65000 | | 85000 | | 105000 | | 7500 | | 25700 | | 32500 | | 45000 | +--------+ 8 rows in set (0.00 sec) mysql> select sum(precio)valor_total from libro; +-------------+ | valor_total | +-------------+ | 420700 | +-------------+ 1 row in set (0.00 sec) mysql> select sum(precio) 'valor_total' from libro; +-------------+ | valor_total | +-------------+ | 420700 | +-------------+ 1 row in set (0.00 sec) mysql> select max(precio) 'libro mas costoso' from libro; +-------------------+ | libro mas costoso | +-------------------+ | 105000 | +-------------------+ 1 row in set (0.00 sec) mysql> select min(precio) 'libro menos costoso' from libro; +---------------------+ | libro menos costoso | +---------------------+ | 7500 | +---------------------+ 1 row in set (0.00 sec) //Consultas con condiciones mysql> select * from libro where precio>50000; +---------+---------------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+---------------------+-----------+--------+-----------+ | L01 | Calculo ll | 120 | 55000 | M01 | | L02 | BD ll | 150 | 65000 | M09 | | L03 | Estructura de datos | 180 | 85000 | M03 | | L04 | Ingles | 280 | 105000 | M04 | +---------+---------------------+-----------+--------+-----------+ 4 rows in set (0.00 sec) mysql> select * from libro where precio<50000; +---------+---------------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+---------------------+-----------+--------+-----------+ | L05 | Admon en una pagina | 70 | 7500 | M05 | | L06 | Contabilidad | 170 | 25700 | M06 | | L07 | Redes | 370 | 32500 | M07 | | L08 | Diagramacion | 85 | 45000 | M08 | +---------+---------------------+-----------+--------+-----------+ 4 rows in set (0.00 sec) mysql> select * from libro where nropagina<100; +---------+---------------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+---------------------+-----------+--------+-----------+ | L05 | Admon en una pagina | 70 | 7500 | M05 | | L08 | Diagramacion | 85 | 45000 | M08 | +---------+---------------------+-----------+--------+-----------+ 2 rows in set (0.00 sec) mysql> select * from libro where nropagina>100; +---------+---------------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+---------------------+-----------+--------+-----------+ | L01 | Calculo ll | 120 | 55000 | M01 | | L02 | BD ll | 150 | 65000 | M09 | | L03 | Estructura de datos | 180 | 85000 | M03 | | L04 | Ingles | 280 | 105000 | M04 | | L06 | Contabilidad | 170 | 25700 | M06 | | L07 | Redes | 370 | 32500 | M07 | +---------+---------------------+-----------+--------+-----------+ 6 rows in set (0.00 sec) mysql> select descripcion, precio from libro where precio<30000; +---------------------+--------+ | descripcion | precio | +---------------------+--------+ | Admon en una pagina | 7500 | | Contabilidad | 25700 | +---------------------+--------+ 2 rows in set (0.00 sec) mysql> select * from libro where precio>50000 and precio<100000; +---------+---------------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+---------------------+-----------+--------+-----------+ | L01 | Calculo ll | 120 | 55000 | M01 | | L02 | BD ll | 150 | 65000 | M09 | | L03 | Estructura de datos | 180 | 85000 | M03 | +---------+---------------------+-----------+--------+-----------+ 3 rows in set (0.00 sec) mysql> select * from libro where precio between 40000 and 100000; +---------+---------------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+---------------------+-----------+--------+-----------+ | L01 | Calculo ll | 120 | 55000 | M01 | | L02 | BD ll | 150 | 65000 | M09 | | L03 | Estructura de datos | 180 | 85000 | M03 | | L08 | Diagramacion | 85 | 45000 | M08 | +---------+---------------------+-----------+--------+-----------+ 4 rows in set (0.00 sec) mysql> select * from libro where idlibro between 'L01' and 'L02'; +---------+-------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+-------------+-----------+--------+-----------+ | L01 | Calculo ll | 120 | 55000 | M01 | | L02 | BD ll | 150 | 65000 | M09 | +---------+-------------+-----------+--------+-----------+ 2 rows in set (0.00 sec) //Comando like mysql> select * from libro where descripcion like 'C%'; +---------+--------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+--------------+-----------+--------+-----------+ | L01 | Calculo ll | 120 | 55000 | M01 | | L06 | Contabilidad | 170 | 25700 | M06 | +---------+--------------+-----------+--------+-----------+ 2 rows in set (0.00 sec) mysql> select * from libro where descripcion like '%a'; +---------+---------------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+---------------------+-----------+--------+-----------+ | L05 | Admon en una pagina | 70 | 7500 | M05 | +---------+---------------------+-----------+--------+-----------+ 1 row in set (0.00 sec) mysql> select * from libro where descripcion like '%a%'; +---------+---------------------+-----------+--------+-----------+ | idlibro | descripcion | nropagina | precio | codigomat | +---------+---------------------+-----------+--------+-----------+ | L01 | Calculo ll | 120 | 55000 | M01 | | L03 | Estructura de datos | 180 | 85000 | M03 | | L05 | Admon en una pagina | 70 | 7500 | M05 | | L06 | Contabilidad | 170 | 25700 | M06 | | L08 | Diagramacion | 85 | 45000 | M08 | +---------+---------------------+-----------+--------+-----------+ 5 rows in set (0.00 sec)