mysql> select sum(val_lib) from libro; +--------------+ | sum(val_lib) | +--------------+ | 707000 | +--------------+ 1 row in set (0.00 sec) mysql> select max(val_lib) from libro; +--------------+ | max(val_lib) | +--------------+ | 130000 | +--------------+ 1 row in set (0.00 sec) mysql> select max(val_lib) from libro; +--------------+ | max(val_lib) | +--------------+ | 130000 | +--------------+ 1 row in set (0.00 sec) mysql> select avg(val_lib) from libro; +--------------+ | avg(val_lib) | +--------------+ | 70700 | +--------------+ 1 row in set (0.00 sec) mysql> select val_lib from libro; +---------+ | val_lib | +---------+ | 100000 | | 25000 | | 55000 | | 50000 | | 50000 | | 70000 | | 72000 | | 75000 | | 80000 | | 130000 | +---------+ 10 rows in set (0.00 sec) mysql> select sum(val_lib)valor_total from libro; +-------------+ | valor_total | +-------------+ | 707000 | +-------------+ 1 row in set (0.00 sec) mysql> select sum(val_lib) 'valor_total' from libro; +-------------+ | valor_total | +-------------+ | 707000 | +-------------+ 1 row in set (0.02 sec) mysql> select max(val_lib)'libro mas costoso' from libro; +-------------------+ | libro mas costoso | +-------------------+ | 130000 | +-------------------+ 1 row in set (0.00 sec) mysql> select min(val_lib)'libro menos costoso' from libro; +---------------------+ | libro menos costoso | +---------------------+ | 25000 | +---------------------+ 1 row in set (0.00 sec) mysql> describe libro; +---------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+----------+------+-----+---------+-------+ | cod_lib | char(10) | NO | PRI | NULL | | | nom_lib | char(40) | NO | | NULL | | | val_lib | float | NO | | NULL | | | fec_lib | date | NO | | NULL | | +---------+----------+------+-----+---------+-------+ 4 rows in set (0.08 sec) mysql> alter table libro add can_lib int(3) not null; Query OK, 0 rows affected (0.56 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe libro; +---------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+----------+------+-----+---------+-------+ | cod_lib | char(10) | NO | PRI | NULL | | | nom_lib | char(40) | NO | | NULL | | | val_lib | float | NO | | NULL | | | fec_lib | date | NO | | NULL | | | can_lib | int(3) | NO | | NULL | | +---------+----------+------+-----+---------+-------+ 5 rows in set (0.03 sec) mysql> select * from libro; +---------+--------------------------------------+---------+------------+---------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | +---------+--------------------------------------+---------+------------+---------+ | 0001 | lo que el viento se llevo | 100000 | 2000-12-20 | 0 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 0 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 0 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 0 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 0 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 0 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 0 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 0 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 0 | | 0010 | LOS HERMANOS KAMARAZOV | 130000 | 1900-09-05 | 0 | +---------+--------------------------------------+---------+------------+---------+ 10 rows in set (0.00 sec) mysql> select * from libro; +---------+--------------------------------------+---------+------------+---------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | +---------+--------------------------------------+---------+------------+---------+ | 0001 | lo que el viento se llevo | 100000 | 2000-12-20 | 0 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 0 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 0 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 0 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 0 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 0 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 0 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 0 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 0 | | 0010 | LOS HERMANOS KAMARAZOV | 130000 | 1900-09-05 | 0 | +---------+--------------------------------------+---------+------------+---------+ 10 rows in set (0.00 sec) mysql> update libro set can_lib=5 where cod_lib='0001'; Query OK, 1 row affected (0.09 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from libro; +---------+--------------------------------------+---------+------------+---------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | +---------+--------------------------------------+---------+------------+---------+ | 0001 | lo que el viento se llevo | 100000 | 2000-12-20 | 5 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 0 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 0 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 0 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 0 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 0 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 0 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 0 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 0 | | 0010 | LOS HERMANOS KAMARAZOV | 130000 | 1900-09-05 | 0 | +---------+--------------------------------------+---------+------------+---------+ 10 rows in set (0.00 sec) mysql> select (val_lib * can_lib)'valor total libros' from libro; +--------------------+ | valor total libros | +--------------------+ | 500000 | | 0 | | 0 | | 0 | | 0 | | 0 | | 0 | | 0 | | 0 | | 0 | +--------------------+ 10 rows in set (0.02 sec) mysql> update libro set can_lib=30 where cod_lib='0002'; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update libro set can_lib=730 where cod_lib='0003'; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update libro set can_lib=100 where cod_lib='0004'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update libro set can_lib=10 where cod_lib='0005'; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update libro set can_lib=999 where cod_lib='0006'; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update libro set can_lib=14 where cod_lib='0007'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update libro set can_lib=300 where cod_lib='0008'; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update libro set can_lib=623 where cod_lib='0009'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update libro set can_lib=210 where cod_lib='0009'; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from libro; +---------+--------------------------------------+---------+------------+---------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | +---------+--------------------------------------+---------+------------+---------+ | 0001 | lo que el viento se llevo | 100000 | 2000-12-20 | 5 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 30 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 730 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 100 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 10 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 999 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 14 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 300 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 210 | | 0010 | LOS HERMANOS KAMARAZOV | 130000 | 1900-09-05 | 0 | +---------+--------------------------------------+---------+------------+---------+ 10 rows in set (0.00 sec) mysql> update libro set nom_lib='LO QUE EL VIENTO SE LLEVO' where cod_lib='0001'; Query OK, 1 row affected (0.23 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from libro; +---------+--------------------------------------+---------+------------+---------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | +---------+--------------------------------------+---------+------------+---------+ | 0001 | LO QUE EL VIENTO SE LLEVO | 100000 | 2000-12-20 | 5 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 30 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 730 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 100 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 10 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 999 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 14 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 300 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 210 | | 0010 | LOS HERMANOS KAMARAZOV | 130000 | 1900-09-05 | 0 | +---------+--------------------------------------+---------+------------+---------+ 10 rows in set (0.00 sec) mysql> alter table libro add tot_lib float(10) not null; Query OK, 0 rows affected (0.31 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select * from libro; +---------+--------------------------------------+---------+------------+---------+---------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | tot_lib | +---------+--------------------------------------+---------+------------+---------+---------+ | 0001 | LO QUE EL VIENTO SE LLEVO | 100000 | 2000-12-20 | 5 | 0 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 30 | 0 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 730 | 0 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 100 | 0 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 10 | 0 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 999 | 0 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 14 | 0 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 300 | 0 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 210 | 0 | | 0010 | LOS HERMANOS KAMARAZOV | 130000 | 1900-09-05 | 0 | 0 | +---------+--------------------------------------+---------+------------+---------+---------+ 10 rows in set (0.00 sec) mysql> update libro set tot_lib=can_lib*val_lib; Query OK, 9 rows affected (0.03 sec) Rows matched: 10 Changed: 9 Warnings: 0 mysql> select * from libro; +---------+--------------------------------------+---------+------------+---------+----------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | tot_lib | +---------+--------------------------------------+---------+------------+---------+----------+ | 0001 | LO QUE EL VIENTO SE LLEVO | 100000 | 2000-12-20 | 5 | 500000 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 30 | 750000 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 730 | 40150000 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 100 | 5000000 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 10 | 500000 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 999 | 69930000 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 14 | 1008000 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 300 | 22500000 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 210 | 16800000 | | 0010 | LOS HERMANOS KAMARAZOV | 130000 | 1900-09-05 | 0 | 0 | +---------+--------------------------------------+---------+------------+---------+----------+ 10 rows in set (0.00 sec) mysql> update libro set can_lib=5 where cod_lib='0010'; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from libro; +---------+--------------------------------------+---------+------------+---------+----------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | tot_lib | +---------+--------------------------------------+---------+------------+---------+----------+ | 0001 | LO QUE EL VIENTO SE LLEVO | 100000 | 2000-12-20 | 5 | 500000 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 30 | 750000 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 730 | 40150000 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 100 | 5000000 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 10 | 500000 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 999 | 69930000 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 14 | 1008000 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 300 | 22500000 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 210 | 16800000 | | 0010 | LOS HERMANOS KAMARAZOV | 130000 | 1900-09-05 | 5 | 0 | +---------+--------------------------------------+---------+------------+---------+----------+ 10 rows in set (0.00 sec) mysql> select * from libro where can_lib>20; +---------+--------------------------------------+---------+------------+---------+----------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | tot_lib | +---------+--------------------------------------+---------+------------+---------+----------+ | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 30 | 750000 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 730 | 40150000 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 100 | 5000000 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 999 | 69930000 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 300 | 22500000 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 210 | 16800000 | +---------+--------------------------------------+---------+------------+---------+----------+ 6 rows in set (0.02 sec) mysql> select nom_lib, val_lib from libro where val_lib<30000; +--------------------------------------+---------+ | nom_lib | val_lib | +--------------------------------------+---------+ | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | +--------------------------------------+---------+ 1 row in set (0.00 sec) mysql> update libro set tot_lib=can_lib*val_lib; Query OK, 1 row affected (0.03 sec) Rows matched: 10 Changed: 1 Warnings: 0 mysql> select * from libro; +---------+--------------------------------------+---------+------------+---------+----------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | tot_lib | +---------+--------------------------------------+---------+------------+---------+----------+ | 0001 | LO QUE EL VIENTO SE LLEVO | 100000 | 2000-12-20 | 5 | 500000 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 30 | 750000 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 730 | 40150000 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 100 | 5000000 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 10 | 500000 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 999 | 69930000 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 14 | 1008000 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 300 | 22500000 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 210 | 16800000 | | 0010 | LOS HERMANOS KAMARAZOV | 130000 | 1900-09-05 | 5 | 650000 | +---------+--------------------------------------+---------+------------+---------+----------+ 10 rows in set (0.00 sec) mysql> select nom_lib, val_lib from libro where val_lib<30000; +--------------------------------------+---------+ | nom_lib | val_lib | +--------------------------------------+---------+ | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | +--------------------------------------+---------+ 1 row in set (0.00 sec) mysql> /* esto es un comentario*/ mysql> mysql> /* esto es un comentario*/ mysql> /* toda la informacion de los libros cuyo valor unitario este entre 50.000 y 100.000*/ mysql> select * from libro where val_lib>=50000 AND val_lib<=100000; +---------+------------------------------+---------+------------+---------+----------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | tot_lib | +---------+------------------------------+---------+------------+---------+----------+ | 0001 | LO QUE EL VIENTO SE LLEVO | 100000 | 2000-12-20 | 5 | 500000 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 730 | 40150000 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 100 | 5000000 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 10 | 500000 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 999 | 69930000 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 14 | 1008000 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 300 | 22500000 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 210 | 16800000 | +---------+------------------------------+---------+------------+---------+----------+ 8 rows in set (0.00 sec) mysql> select * from libro where val_lib between 50000 and 100000; +---------+------------------------------+---------+------------+---------+----------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | tot_lib | +---------+------------------------------+---------+------------+---------+----------+ | 0001 | LO QUE EL VIENTO SE LLEVO | 100000 | 2000-12-20 | 5 | 500000 | | 0003 | EL PELAITO QUE NO DURO NADA | 55000 | 1986-02-28 | 730 | 40150000 | | 0004 | MI ALMA SE LA DEJO AL DIABLO | 50000 | 1982-03-22 | 100 | 5000000 | | 0005 | EL HUECO | 50000 | 1978-11-15 | 10 | 500000 | | 0006 | ANA KARENINA | 70000 | 1918-05-20 | 999 | 69930000 | | 0007 | LOS MISERABLES | 72000 | 1920-07-12 | 14 | 1008000 | | 0008 | EL OLVIDO QUE SEREMOS | 75000 | 1990-07-24 | 300 | 22500000 | | 0009 | CRIMEN Y CASTIGO | 80000 | 1930-08-16 | 210 | 16800000 | +---------+------------------------------+---------+------------+---------+----------+ 8 rows in set (0.01 sec) mysql> /*visualizar toda la informacion de los libros cuyos codigos sean 0001, 0002 y 003 */ mysql> select * from libro where cod_lib between '0001' and '0002' and '003'; +---------+--------------------------------------+---------+------------+---------+---------+ | cod_lib | nom_lib | val_lib | fec_lib | can_lib | tot_lib | +---------+--------------------------------------+---------+------------+---------+---------+ | 0001 | LO QUE EL VIENTO SE LLEVO | 100000 | 2000-12-20 | 5 | 500000 | | 0002 | EL CORONEL NO TIENE QUIEN LE ESCRIBA | 25000 | 1985-01-10 | 30 | 750000 | +---------+--------------------------------------+---------+------------+---------+---------+ 2 rows in set (0.02 sec)