BASE DE DATOS LIBRERIA
Primero debe crear el model entidad relacion y el diagrama relacional en excel.
pendiente montar entidad relacional

Cree en Mysql la base de datos llamada libreria.
Cree las siguientes tablas con sus respectivos registros.
Nota: el precio y nro de p�gina deben ser ingresados como enteros. Los dem�s campos tipo char.
Debe quedar constancia en el bloc de notas de la realizaci�n de cada consulta y adem�s debe exportar
los resultados a excel.
Cambiar el campo t�tulo por descripcion
solucion:
LIBRO
+---------+---------------------+-----------+--------+-----------+
| idlibro | titulo | nropagina | precio | codigomat |
+---------+---------------------+-----------+--------+-----------+
| L01 | Calculo II | 120 | 55000 | M01 |
| L02 | BD II | 150 | 65000 | M09 |
| L03 | Estructura de datos | 180 | 85000 | M03 |
| L08 | Diagramacion | 85 | 45000 | M08 |
| L05 | Admon en una pagina | 70 | 7500 | M05 |
| L06 | Contabilidad I | 170 | 27500 | M06 |
| L07 | Redes | 370 | 32500 | M07 |
| L04 | Ingles | 280 | 105000 | M04 |
+---------+---------------------+-----------+--------+-----------+
MATERIA
+-----------+---------------------+
| codigomat | nombre |
+-----------+---------------------+
| M01 | Calculo |
| M02 | Matematicas |
| M03 | Estructura de datos |
| M04 | Ingl |
| M08 | Diagramacion |
| M06 | Contabilidad |
| M07 | Redes |
| M05 | Sistemas de Inf. |
| M09 | Base de datos |
+-----------+---------------------+
AUTOR
+----------+----------------------+
| codautor | nombre |
+----------+----------------------+
| A01 | Luis Joyanes |
| A02 | Jorge Vasquez Posada |
| A03 | Jhon Soars |
| A04 | Riaz Khadem |
| A05 | Robert Lorber |
| A06 | Mario Dream |
+----------+----------------------+
EDITORIAL
++---------+--------------+
| codedit | nombre |
+---------+--------------+
| E01 | Oveja Negra |
| E02 | Norma |
| E03 | Mc Graw Hill |
+---------+--------------+
LIAUTEDI
+---------+----------+---------+
| idlibro | codautor | codedit |
+---------+----------+---------+
| L02 | A01 | E01 |
| L02 | A05 | E03 |
| L06 | A02 | E02 |
| L07 | A05 | E03 |
| L04 | A04 | E01 |
| L04 | A04 | E02 |
| L04 | A04 | E03 |
+---------+----------+---------+
A CONTINUACION
a. Listar lo libros
mysql> select idlibro,descripcion,nropagina,precio,codigomat from libro;
+---------+---------------------+-----------+--------+-----------+
| idlibro | descripcion | nropagina | precio | codigomat |
+---------+---------------------+-----------+--------+-----------+
| L01 | Calculo II | 120 | 55000 | M01 |
| L02 | BD II | 150 | 65000 | M09 |
| L03 | Estructara de Datos | 180 | 85000 | M03 |
| L04 | Ingles | 280 | 105000 | M04 |
| L05 | Admon en una Pagina | 70 | 7500 | M05 |
| L06 | Contabilidad I | 170 | 27500 | M06 |
| L07 | Redes | 370 | 32500 | M07 |
| L08 | Diagramacion | 85 | 45000 | M08 |
+---------+---------------------+-----------+--------+-----------+
8 rows in set (0.00 sec)
b. listar los autores.
mysql> select codautor,nombre from autor;
+----------+----------------------+
| codautor | 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)
c. Listar las editoriales.
mysql> select codedit,nombre from editorial;
+---------+--------------+
| codedit | nombre |
+---------+--------------+
| E01 | Oveja Negra |
| E02 | Norma |
| E03 | Mc Graw Hill |
+---------+--------------+
3 rows in set (0.00 sec)
d. listar las materias
mysql> select codigomat,nombre from materia;
+-----------+---------------------+
| codigomat | nombre |
+-----------+---------------------+
| M01 | Calculo |
| M02 | Matematicas |
| M03 | Estructura de Datos |
| M04 | Ingles |
| M05 | Sistemas de Inf. |
| M06 | Contabilidad |
| M07 | Redes |
| M08 | Diagramacion |
| M09 | Bases de Datos |
+-----------+---------------------+
9 rows in set (0.00 sec)
e. Listar la descripcion de los libros y los precios.
mysql> select descripcion,precio from libro;
+---------------------+--------+
| descripcion | precio |
+---------------------+--------+
| Calculo II | 55000 |
| BD II | 65000 |
| Estructara de Datos | 85000 |
| Ingles | 105000 |
| Admon en una Pagina | 7500 |
| Contabilidad I | 27500 |
| Redes | 32500 |
| Diagramacion | 45000 |
+---------------------+--------+
8 rows in set (0.00 sec)
f. Cambiar el nombre de la tabla materia por asignatura
mysql> alter table materia rename to asignatura;
Query OK, 0 rows affected (0.01 sec)
g. Realizar consultas con el comando like y con condiciones
mysql> select *from autor where nombre like'R';
Empty set (0.02 sec)
mysql> select *from autor where nombre like'%R';
+----------+---------------+
| codautor | nombre |
+----------+---------------+
| A05 | Robert Lorber |
+----------+---------------+
1 row in set (0.00 sec)
mysql> select *from autor where nombre like'%r';
+----------+---------------+
| codautor | nombre |
+----------+---------------+
| A05 | Robert Lorber |
+----------+---------------+
1 row in set (0.00 sec)
mysql> select *from autor where nombre like'r%';
+----------+---------------+
| codautor | nombre |
+----------+---------------+
| A04 | Riaz Khadem |
| A05 | Robert Lorber |
+----------+---------------+
2 rows in set (0.00 sec)
mysql> select *from autor where nombre like'%r%';
+----------+----------------------+
| codautor | nombre |
+----------+----------------------+
| A02 | Jorge Vasquez Posada |
| A03 | Jhon Soars |
| A04 | Riaz Khadem |
| A05 | Robert Lorber |
| A06 | Mario Dream |
+----------+----------------------+
5 rows in set (0.00 sec)
mysql> select *from autor where nombre like'%s%';
+----------+----------------------+
| codautor | nombre |
+----------+----------------------+
| A01 | Luis Joyanes |
| A02 | Jorge Vasquez Posada |
| A03 | Jhon Soars |
+----------+----------------------+
3 rows in set (0.00 sec)
mysql> select *from autor where nombre like'%s';
+----------+--------------+
| codautor | nombre |
+----------+--------------+
| A01 | Luis Joyanes |
| A03 | Jhon Soars |
+----------+--------------+
2 rows in set (0.00 sec)
mysql> select *from autor where nombre like's%';
Empty set (0.00 sec)
con condiciones
mysql> select * from libro where descripcion like'%II%' and precio>=650000;
Empty set (0.00 sec)
mysql> select * from libro where descripcion like'%II%' or precio>=27500;
+---------+---------------------+-----------+--------+-----------+
| idlibro | descripcion | nropagina | precio | codigomat |
+---------+---------------------+-----------+--------+-----------+
| L01 | Calculo II | 120 | 55000 | M01 |
| L02 | BD II | 150 | 65000 | M09 |
| L03 | Estructara de Datos | 180 | 85000 | M03 |
| L04 | Ingles | 280 | 105000 | M04 |
| L06 | Contabilidad I | 170 | 27500 | M06 |
| L07 | Redes | 370 | 32500 | M07 |
| L08 | Diagramacion | 85 | 45000 | M08 |
+---------+---------------------+-----------+--------+-----------+
7 rows in set (0.00 sec)
h: Utilizar la funciones para realizar calculos en las tablas donde crea que puede hacerlo.
mysql> select sum(precio) from libro;
+-------------+
| sum(precio) |
+-------------+
| 422500 |
+-------------+
1 row in set (0.05 sec)
mysql> select avg(nropagina)'promedio de paginas' from libro;
+---------------------+
| promedio de paginas |
+---------------------+
| 178.1250 |
+---------------------+
1 row in set (0.01 sec)
mysql> select max(precio)'libro mas costoso' from libro;
+-------------------+
| libro mas costoso |
+-------------------+
| 105000 |
+-------------------+
1 row in set (0.02 sec)