MariaDB [prestamos]> select * from prestamo where fecha_solicitud >= curdate() - interval 60 day; Empty set (0.137 sec) MariaDB [prestamos]> select * from prestamos where fecha_solicitud >= curdate() - interval 60 day; ERROR 1146 (42S02): Table 'prestamos.prestamos' doesn't exist MariaDB [prestamos]> show tables; +---------------------+ | Tables_in_prestamos | +---------------------+ | cliente | | cobradores | | condicionesprestamo | | garantias | | historialprestamo | | multas | | multprest | | municipios | | pago | | planpago | | prestamo | | refclient | | referencias | | renegociaciones | | zonas | +---------------------+ 15 rows in set (0.001 sec) MariaDB [prestamos]> insert into prestamo (codigo_prestamo, id_cliente, monto_prestado, fecha_solicitud, estado) values(8881, 10, 800000, '2025-04-05', 'Aprobado'), -> (8882, 20, 500000, '2025-04-20', 'En proceso'), -> (8883, 30, 600000, curdate(), 'Activo'); Query OK, 3 rows affected (0.032 sec) Records: 3 Duplicates: 0 Warnings: 0 MariaDB [prestamos]> select * from prestamo where fecha_solicitud >= curdate() - interval 60 day; +-----------------+------------+----------------+-----------------+------------+ | codigo_prestamo | id_cliente | monto_prestado | fecha_solicitud | estado | +-----------------+------------+----------------+-----------------+------------+ | 8881 | 10 | 800000 | 2025-04-05 | Aprobado | | 8882 | 20 | 500000 | 2025-04-20 | En proceso | | 8883 | 30 | 600000 | 2025-05-23 | Activo | +-----------------+------------+----------------+-----------------+------------+ 3 rows in set (0.001 sec) MariaDB [prestamos]> show triggers; +----------------------------+--------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation | +----------------------------+--------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | actualizar_estado_prestamo | INSERT | historialprestamo | begin update prestamo set estado = (select estado_actual from historialprestamo where codigo_historial = new.codigo_historial) where codigo_prestamo = new.codigo_prestamo; END | AFTER | 2025-05-17 10:33:02.45 | NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION | root@localhost | cp850 | cp850_general_ci | utf8mb4_general_ci | +----------------------------+--------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ 1 row in set (0.081 sec) MariaDB [prestamos]> select * from cliente where nombre like '%an%'; +------------+---------------+---------------+------------+-----------------------+----------------------+ | id_cliente | nombre | apellidos | telefono | numero_identificacion | direccion | +------------+---------------+---------------+------------+-----------------------+----------------------+ | 10 | Sandra Milena | S nchez L˘pez | 3012345678 | 187654321 | Itaguˇ | | 20 | Fernando | G˘mez | 3045678910 | 187654322 | San Antonio de Prado | | 30 | Carlos Andr‚s | Gaviria Mesa | 3001234567 | 487654323 | San Antonio de Prado | | 60 | Juan David | Garcˇa Posada | 3156789012 | 187654326 | Itaguˇ | +------------+---------------+---------------+------------+-----------------------+----------------------+ 4 rows in set (0.048 sec) MariaDB [prestamos]> alter table garantias add nivel_riesgo enum ('Alto', 'Medio','Bajo') default 'Medio'; Query OK, 0 rows affected (0.059 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [prestamos]> describe garantias; +-----------------+-----------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+-----------------------------+------+-----+---------+-------+ | id_garantia | int(11) | NO | PRI | NULL | | | codigo_prestamo | int(11) | NO | MUL | NULL | | | tipo_garantia | varchar(50) | NO | | NULL | | | descripcion | varchar(100) | NO | | NULL | | | valorEstimado | decimal(10,2) | NO | | NULL | | | estado_garantia | varchar(50) | NO | | NULL | | | nivel_riesgo | enum('Alto','Medio','Bajo') | YES | | Medio | | +-----------------+-----------------------------+------+-----+---------+-------+ 7 rows in set (0.046 sec) MariaDB [prestamos]> select id_garantia, tipo_garantia, descripcion, nivel_riesgo from garantias; +-------------+------------------+------------------+--------------+ | id_garantia | tipo_garantia | descripcion | nivel_riesgo | +-------------+------------------+------------------+--------------+ | 1111 | Electrodom‚stico | Horno Microondas | Medio | | 1212 | Tecnologˇa | Celular | Medio | | 1313 | Electrodom‚stico | Televisor | Medio | | 1414 | Joyas | Cadenas y reloj | Medio | | 1515 | Electrodom‚stico | Televisor | Medio | | 1616 | Tecnologˇa | Tablet | Medio | | 1717 | Transporte | Bicicleta | Medio | | 1818 | Hogar | Olla arrocera | Medio | | 1919 | Transporte | Moto | Medio | | 2020 | Tecnologˇa | Celular | Medio | +-------------+------------------+------------------+--------------+ 10 rows in set (0.001 sec) MariaDB [prestamos]> update garantias set nivel_riesgo ='Alto' where tipo_garantia = 'joyas'; Query OK, 1 row affected (0.028 sec) Rows matched: 1 Changed: 1 Warnings: 0 MariaDB [prestamos]> select id_garantia, tipo_garantia, descripcion, nivel_riesgo from garantias; +-------------+------------------+------------------+--------------+ | id_garantia | tipo_garantia | descripcion | nivel_riesgo | +-------------+------------------+------------------+--------------+ | 1111 | Electrodom‚stico | Horno Microondas | Medio | | 1212 | Tecnologˇa | Celular | Medio | | 1313 | Electrodom‚stico | Televisor | Medio | | 1414 | Joyas | Cadenas y reloj | Alto | | 1515 | Electrodom‚stico | Televisor | Medio | | 1616 | Tecnologˇa | Tablet | Medio | | 1717 | Transporte | Bicicleta | Medio | | 1818 | Hogar | Olla arrocera | Medio | | 1919 | Transporte | Moto | Medio | | 2020 | Tecnologˇa | Celular | Medio | +-------------+------------------+------------------+--------------+ 10 rows in set (0.001 sec) MariaDB [prestamos]> select c.nombre, p.monto_prestado from cliente c inner join prestamo p on c.id_cliente = p.id_cliente; +---------------+----------------+ | nombre | monto_prestado | +---------------+----------------+ | Sandra Milena | 500000 | | Luis | 400000 | | Jorge | 2000000 | | Fernando | 1000000 | | Carlos Andr‚s | 450000 | | Laura | 300000 | | Sara | 1500000 | | Juan David | 150000 | | Marˇa In‚s | 3500000 | | Claudia | 320000 | | Sandra Milena | 800000 | | Fernando | 500000 | | Carlos Andr‚s | 600000 | +---------------+----------------+ 13 rows in set (0.027 sec) MariaDB [prestamos]> select c.nombre, r.nombre_referente from cliente c left join referencias r on c.id_cliente = r.id_cliente; +---------------+----------------------+ | nombre | nombre_referente | +---------------+----------------------+ | Sandra Milena | Marˇa L˘pez | | Jorge | Camilo Mendoza | | Fernando | Lucˇa G˘mez | | Carlos Andr‚s | Felipe Garcˇa | | Laura | Alejandra Ruiz | | Laura | Manuel Soto | | Sara | Elena Cardona Torres | | Juan David | Juli n Posada | | Marˇa In‚s | Valeria Gil Betancur | | Claudia | Miguel Dˇaz | | Luis | Vanesa Piedrahita | +---------------+----------------------+ 11 rows in set (0.026 sec) MariaDB [prestamos]> select c.nombre, h.estado_actual from historialprestamo h right join cliente c on h.id_cliente = c.id_cliente; +---------------+---------------+ | nombre | estado_actual | +---------------+---------------+ | Sandra Milena | Activo | | Sandra Milena | En mora | | Jorge | Activo | | Fernando | Activo | | Carlos Andr‚s | Cerrado | | Laura | Activo | | Sara | En mora | | Juan David | Cerrado | | Marˇa In‚s | Activo | | Claudia | Activo | | Luis | Activo | +---------------+---------------+ 11 rows in set (0.029 sec) MariaDB [prestamos]> select c.nombre, p.fecha_solicitud, g.tipo_garantia from cliente c join prestamo p on c.id_cliente = p.id_cliente join garantias g on p.codigo_prestamo = g.codigo_prestamo; +---------------+-----------------+------------------+ | nombre | fecha_solicitud | tipo_garantia | +---------------+-----------------+------------------+ | Sandra Milena | 2024-05-15 | Electrodom‚stico | | Luis | 2024-10-05 | Tecnologˇa | | Jorge | 2024-08-10 | Electrodom‚stico | | Fernando | 2024-10-20 | Joyas | | Carlos Andr‚s | 2024-07-16 | Electrodom‚stico | | Laura | 2024-08-12 | Tecnologˇa | | Sara | 2024-06-18 | Transporte | | Juan David | 2024-07-25 | Hogar | | Marˇa In‚s | 2024-08-03 | Transporte | | Claudia | 2024-10-25 | Tecnologˇa | +---------------+-----------------+------------------+ 10 rows in set (0.001 sec) MariaDB [prestamos]> set @n := 0; Query OK, 0 rows affected (0.023 sec) MariaDB [prestamos]> select @n := @n + 1 as numero, id_cliente, monto_multa from multas: -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':' at line 1 MariaDB [prestamos]> select @n := @n + 1 as numero, id_cliente, monto_multa from multas; +--------+------------+-------------+ | numero | id_cliente | monto_multa | +--------+------------+-------------+ | 1 | 50 | 100000 | | 2 | 80 | 150000 | | 3 | 40 | 50000 | | 4 | 10 | 20000 | | 5 | 11 | 75000 | | 6 | 70 | 120000 | | 7 | 90 | 80000 | +--------+------------+-------------+ 7 rows in set (0.026 sec) MariaDB [prestamos]> create table auditoria_pago -> (id int auto_increment not noll primary key, -> codigo_pago int not null, -> accion varchar(10) not null, -> fecha timestamp default current_timestamp); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'noll primary key, codigo_pago int not null, accion varchar(10) not null, fec...' at line 2 MariaDB [prestamos]> create table auditoria_pago -> (id int auto_increment not null primary key, -> codigo_pago int not null, -> accion varchar(10) not null, -> fecha timestamp default current_timestamp); Query OK, 0 rows affected (0.043 sec) MariaDB [prestamos]> delimiter // MariaDB [prestamos]> create trigger auditar_pago after insert on pago for each row begin insert into auditoria_pago (codigo_pago, accion) values (new.codigo_pago, 'INSERT'); -> end ; -> // Query OK, 0 rows affected (0.038 sec) MariaDB [prestamos]> show triggers; -> // +----------------------------+--------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation | +----------------------------+--------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ | actualizar_estado_prestamo | INSERT | historialprestamo | begin update prestamo set estado = (select estado_actual from historialprestamo where codigo_historial = new.codigo_historial) where codigo_prestamo = new.codigo_prestamo; END | AFTER | 2025-05-17 10:33:02.45 | NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION | root@localhost | cp850 | cp850_general_ci | utf8mb4_general_ci | | auditar_pago | INSERT | pago | begin insert into auditoria_pago (codigo_pago, accion) values (new.codigo_pago, 'INSERT'); end | AFTER | 2025-05-23 10:20:13.81 | NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION | root@localhost | cp850 | cp850_general_ci | utf8mb4_general_ci | +----------------------------+--------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------------------------+-----------------------------------------------------+----------------+----------------------+----------------------+--------------------+ 2 rows in set (0.050 sec) MariaDB [prestamos]> insert into pago (codigo_pago, codigo_prestamo, monto_pagado, fecha_pago, metodo_pago, cuotas_restantes) values (1010,110,123000, curdate(), 'Efectivo',2); -> // Query OK, 1 row affected (0.052 sec) MariaDB [prestamos]> select * from auditoria_pago; -> // +----+-------------+--------+---------------------+ | id | codigo_pago | accion | fecha | +----+-------------+--------+---------------------+ | 1 | 1010 | INSERT | 2025-05-23 10:21:45 | +----+-------------+--------+---------------------+ 1 row in set (0.001 sec) MariaDB [prestamos]> create user 'admon@localhost' identified by 'admin'; -> // Query OK, 0 rows affected (0.039 sec) MariaDB [prestamos]> create user 'usuario@localhost' identified by '123456'; -> // Query OK, 0 rows affected (0.027 sec) MariaDB [prestamos]> select user from user; -> // ERROR 1146 (42S02): Table 'prestamos.user' doesn't exist MariaDB [prestamos]> grant all privileges on prestamos.* to 'admon@localhost'; -> // Query OK, 0 rows affected (0.025 sec) MariaDB [prestamos]> grant select on prestamos.* to 'usuario@localhost'; -> // Query OK, 0 rows affected (0.024 sec) MariaDB [prestamos]> flush privileges; -> // Query OK, 0 rows affected (0.002 sec) MariaDB [prestamos]> exit; -> // ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'exit' at line 1 MariaDB [prestamos]> exit