MariaDB [(none)]> use estudiantesfechas; Database changed MariaDB [estudiantesfechas]> show tables; +-----------------------------+ | Tables_in_estudiantesfechas | +-----------------------------+ | auditoria | | estmat | | estudiantes | | materia | +-----------------------------+ 4 rows in set (0.001 sec) MariaDB [estudiantesfechas]> select * from auditoria; Empty set (0.000 sec) MariaDB [estudiantesfechas]> select * from estudiantes; +--------+------------------+----------------+-----------------+------+------+ | carnet | nombre | fechamatricula | fechanacimiento | sexo | edad | +--------+------------------+----------------+-----------------+------+------+ | 1 | maria | 2010-01-15 | 1966-05-13 | f | 59 | | 2 | juana | 2010-06-08 | 1973-01-22 | f | 52 | | 3 | carlos | 2010-06-28 | 1976-03-05 | m | 49 | | 4 | Maria Parra | 2010-06-11 | 1976-08-15 | f | 49 | | 5 | Pablo Neruda | 2011-02-13 | 1990-08-25 | m | 35 | | 6 | Bladimir Palacio | 2011-02-04 | 1994-09-03 | m | 31 | | 7 | Apolonia Serrano | 2011-02-28 | 1994-03-09 | f | 31 | | 8 | Federico Serrano | 2011-03-05 | 1991-06-10 | m | 34 | +--------+------------------+----------------+-----------------+------+------+ 8 rows in set (0.000 sec) MariaDB [estudiantesfechas]> select * from materia; +---------+--------------+--------+ | codigom | descripcion | valor | +---------+--------------+--------+ | 1 | software I | 320000 | | 2 | software II | 328000 | | 3 | software III | 400000 | | 4 | matematicas | 300000 | | 5 | ingles | 300000 | +---------+--------------+--------+ 5 rows in set (0.000 sec) MariaDB [estudiantesfechas]> select * from estmat; +--------+---------+ | carnet | codigom | +--------+---------+ | 1 | 3 | | 1 | 5 | | 2 | 2 | | 2 | 3 | | 2 | 4 | | 3 | 4 | | 3 | 1 | | 4 | 4 | | 4 | 5 | | 5 | 2 | | 5 | 5 | | 6 | 1 | | 6 | 5 | | 7 | 3 | | 7 | 4 | | 8 | 1 | | 8 | 4 | | 8 | 5 | +--------+---------+ 18 rows in set (0.000 sec) MariaDB [estudiantesfechas]> select count(*) as total_estudiantes from estudiantes where year (fechanacimiento)between 1970 and 1979; +-------------------+ | total_estudiantes | +-------------------+ | 3 | +-------------------+ 1 row in set (0.000 sec) MariaDB [estudiantesfechas]> select * from estudiantes where year(current_date())-year(fechanacimiento) between 16 and 20; Empty set (0.000 sec) MariaDB [estudiantesfechas]> select * from estudiantes where year(current_date())-year(fechanacimiento)>25; +--------+------------------+----------------+-----------------+------+------+ | carnet | nombre | fechamatricula | fechanacimiento | sexo | edad | +--------+------------------+----------------+-----------------+------+------+ | 1 | maria | 2010-01-15 | 1966-05-13 | f | 59 | | 2 | juana | 2010-06-08 | 1973-01-22 | f | 52 | | 3 | carlos | 2010-06-28 | 1976-03-05 | m | 49 | | 4 | Maria Parra | 2010-06-11 | 1976-08-15 | f | 49 | | 5 | Pablo Neruda | 2011-02-13 | 1990-08-25 | m | 35 | | 6 | Bladimir Palacio | 2011-02-04 | 1994-09-03 | m | 31 | | 7 | Apolonia Serrano | 2011-02-28 | 1994-03-09 | f | 31 | | 8 | Federico Serrano | 2011-03-05 | 1991-06-10 | m | 34 | +--------+------------------+----------------+-----------------+------+------+ 8 rows in set (0.000 sec) MariaDB [estudiantesfechas]> select nombre, year(current_date()) - year(fechanacimiento) 'edad' from estudiantes ; +------------------+------+ | nombre | edad | +------------------+------+ | maria | 59 | | juana | 52 | | carlos | 49 | | Maria Parra | 49 | | Pablo Neruda | 35 | | Bladimir Palacio | 31 | | Apolonia Serrano | 31 | | Federico Serrano | 34 | +------------------+------+ 8 rows in set (0.000 sec) MariaDB [estudiantesfechas]> select codigom,valor, descripcion, case when valor >300000 then 'cara' else 'economica' end as categoria from materia; +---------+--------+--------------+-----------+ | codigom | valor | descripcion | categoria | +---------+--------+--------------+-----------+ | 1 | 320000 | software I | cara | | 2 | 328000 | software II | cara | | 3 | 400000 | software III | cara | | 4 | 300000 | matematicas | economica | | 5 | 300000 | ingles | economica | +---------+--------+--------------+-----------+ 5 rows in set (0.000 sec) MariaDB [estudiantesfechas]> alter table estudiantes add column edad int; ERROR 1060 (42S21): Duplicate column name 'edad' MariaDB [estudiantesfechas]> alter table estudiantes drop column edad; Query OK, 0 rows affected (0.053 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [estudiantesfechas]> select * from estudiantes; +--------+------------------+----------------+-----------------+------+ | carnet | nombre | fechamatricula | fechanacimiento | sexo | +--------+------------------+----------------+-----------------+------+ | 1 | maria | 2010-01-15 | 1966-05-13 | f | | 2 | juana | 2010-06-08 | 1973-01-22 | f | | 3 | carlos | 2010-06-28 | 1976-03-05 | m | | 4 | Maria Parra | 2010-06-11 | 1976-08-15 | f | | 5 | Pablo Neruda | 2011-02-13 | 1990-08-25 | m | | 6 | Bladimir Palacio | 2011-02-04 | 1994-09-03 | m | | 7 | Apolonia Serrano | 2011-02-28 | 1994-03-09 | f | | 8 | Federico Serrano | 2011-03-05 | 1991-06-10 | m | +--------+------------------+----------------+-----------------+------+ 8 rows in set (0.000 sec) MariaDB [estudiantesfechas]> alter table estudiantes add column edad int; Query OK, 0 rows affected (0.056 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [estudiantesfechas]> select * from estudiantes; +--------+------------------+----------------+-----------------+------+------+ | carnet | nombre | fechamatricula | fechanacimiento | sexo | edad | +--------+------------------+----------------+-----------------+------+------+ | 1 | maria | 2010-01-15 | 1966-05-13 | f | NULL | | 2 | juana | 2010-06-08 | 1973-01-22 | f | NULL | | 3 | carlos | 2010-06-28 | 1976-03-05 | m | NULL | | 4 | Maria Parra | 2010-06-11 | 1976-08-15 | f | NULL | | 5 | Pablo Neruda | 2011-02-13 | 1990-08-25 | m | NULL | | 6 | Bladimir Palacio | 2011-02-04 | 1994-09-03 | m | NULL | | 7 | Apolonia Serrano | 2011-02-28 | 1994-03-09 | f | NULL | | 8 | Federico Serrano | 2011-03-05 | 1991-06-10 | m | NULL | +--------+------------------+----------------+-----------------+------+------+ 8 rows in set (0.000 sec) MariaDB [estudiantesfechas]> update estudiantes set edad = year (current_date())-year(fechanacimiento); Query OK, 8 rows affected (0.048 sec) Rows matched: 8 Changed: 8 Warnings: 0 MariaDB [estudiantesfechas]> select * from estudiantes; +--------+------------------+----------------+-----------------+------+------+ | carnet | nombre | fechamatricula | fechanacimiento | sexo | edad | +--------+------------------+----------------+-----------------+------+------+ | 1 | maria | 2010-01-15 | 1966-05-13 | f | 59 | | 2 | juana | 2010-06-08 | 1973-01-22 | f | 52 | | 3 | carlos | 2010-06-28 | 1976-03-05 | m | 49 | | 4 | Maria Parra | 2010-06-11 | 1976-08-15 | f | 49 | | 5 | Pablo Neruda | 2011-02-13 | 1990-08-25 | m | 35 | | 6 | Bladimir Palacio | 2011-02-04 | 1994-09-03 | m | 31 | | 7 | Apolonia Serrano | 2011-02-28 | 1994-03-09 | f | 31 | | 8 | Federico Serrano | 2011-03-05 | 1991-06-10 | m | 34 | +--------+------------------+----------------+-----------------+------+------+ 8 rows in set (0.000 sec) MariaDB [estudiantesfechas]> select carnet, nombre, edad, case when edad > 30 then 'hombre mayor' else 'joven en desarrollo' end as categoria from estudiantes; +--------+------------------+------+--------------+ | carnet | nombre | edad | categoria | +--------+------------------+------+--------------+ | 1 | maria | 59 | hombre mayor | | 2 | juana | 52 | hombre mayor | | 3 | carlos | 49 | hombre mayor | | 4 | Maria Parra | 49 | hombre mayor | | 5 | Pablo Neruda | 35 | hombre mayor | | 6 | Bladimir Palacio | 31 | hombre mayor | | 7 | Apolonia Serrano | 31 | hombre mayor | | 8 | Federico Serrano | 34 | hombre mayor | +--------+------------------+------+--------------+ 8 rows in set (0.000 sec) MariaDB [estudiantesfechas]> select codigom, descripcion, valor, case when valor > 200000 and valor <= 300000 then 'materia economica' else 'cara' end as categoria from materia; +---------+--------------+--------+-------------------+ | codigom | descripcion | valor | categoria | +---------+--------------+--------+-------------------+ | 1 | software I | 320000 | cara | | 2 | software II | 328000 | cara | | 3 | software III | 400000 | cara | | 4 | matematicas | 300000 | materia economica | | 5 | ingles | 300000 | materia economica | +---------+--------------+--------+-------------------+ 5 rows in set (0.000 sec) MariaDB [estudiantesfechas]>