2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`riskAllClients`(maxRiskDate DATE)
|
|
|
|
BEGIN
|
|
|
|
|
2024-04-08 10:01:27 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
|
|
|
CREATE TEMPORARY TABLE tmp.client_list
|
|
|
|
(PRIMARY KEY (Id_Cliente))
|
2024-01-15 11:31:03 +00:00
|
|
|
ENGINE = MEMORY
|
2024-04-08 10:01:27 +00:00
|
|
|
SELECT id Id_Cliente, null grade FROM vn.client;
|
2024-03-06 11:02:34 +00:00
|
|
|
|
2024-04-08 10:01:27 +00:00
|
|
|
CALL vn2008.risk_vs_client_list(maxRiskDate);
|
2024-03-06 11:02:34 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT
|
2024-04-08 10:01:27 +00:00
|
|
|
c.RazonSocial,
|
|
|
|
c.Id_Cliente,
|
|
|
|
c.Credito,
|
|
|
|
CAST(r.risk as DECIMAL (10,2)) risk,
|
|
|
|
CAST(c.Credito - r.risk as DECIMAL (10,2)) Diferencia,
|
|
|
|
c.Id_Pais
|
|
|
|
FROM
|
|
|
|
vn2008.Clientes c
|
|
|
|
JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente
|
|
|
|
JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente
|
|
|
|
GROUP BY c.Id_cliente;
|
2024-03-06 11:02:34 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
|
2024-04-08 10:01:27 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|