2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost`
|
2024-01-15 11:31:03 +00:00
|
|
|
SQL SECURITY DEFINER
|
|
|
|
VIEW `vn`.`clientLost`
|
|
|
|
AS SELECT `c`.`id` AS `clientFk`,
|
|
|
|
max(`t`.`shipped`) AS `lastShipped`,
|
|
|
|
`pc`.`notBuyingMonths` AS `notBuyingMonths`
|
|
|
|
FROM (
|
|
|
|
(
|
|
|
|
`vn`.`client` `c`
|
|
|
|
JOIN `vn`.`productionConfig` `pc`
|
|
|
|
)
|
|
|
|
LEFT JOIN `vn`.`ticket` `t` ON(
|
|
|
|
`c`.`id` = `t`.`clientFk`
|
|
|
|
AND `t`.`shipped` < `util`.`VN_CURDATE`() + INTERVAL - `pc`.`rookieDays` DAY
|
|
|
|
)
|
|
|
|
)
|
|
|
|
GROUP BY `c`.`id`
|
|
|
|
HAVING `lastShipped` IS NULL
|
|
|
|
OR `lastShipped` < `util`.`VN_CURDATE`() + INTERVAL - `notBuyingMonths` MONTH
|