2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`()
|
|
|
|
BEGIN
|
2024-03-21 09:40:30 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
2024-01-15 11:31:03 +00:00
|
|
|
CREATE TEMPORARY TABLE tmp.client_list
|
2024-03-21 09:40:30 +00:00
|
|
|
(PRIMARY KEY (Id_Cliente))
|
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT * FROM (
|
|
|
|
SELECT cc.client, ci.grade
|
|
|
|
FROM creditClassification cc
|
|
|
|
JOIN creditInsurance ci ON cc.id = ci.creditClassification
|
|
|
|
WHERE dateEnd IS NULL
|
|
|
|
ORDER BY ci.creationDate DESC
|
|
|
|
LIMIT 10000000000000000000) t1
|
|
|
|
GROUP BY client;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
CALL vn2008.risk_vs_client_list(util.VN_CURDATE());
|
2024-03-21 09:40:30 +00:00
|
|
|
|
|
|
|
SELECT
|
|
|
|
c.id,
|
|
|
|
c.name,
|
|
|
|
c.credit clientCredit,
|
|
|
|
c.creditInsurance solunion,
|
|
|
|
cast(r.risk as DECIMAL(10,0)) risk,
|
|
|
|
cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive,
|
|
|
|
cac.invoiced billedAnnually,
|
|
|
|
c.dueDay,
|
|
|
|
ci.grade,
|
|
|
|
c2.country
|
|
|
|
FROM tmp.client_list ci
|
|
|
|
LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.client
|
|
|
|
JOIN client c ON c.id = ci.client
|
|
|
|
JOIN bs.clientAnnualConsumption cac ON c.id = cac.Id_Cliente
|
|
|
|
JOIN vn.country c2 ON c2.id = c.countryFk
|
|
|
|
GROUP BY c.id;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
|
2024-01-15 11:31:03 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|