salix/db/routines/vn/views/clientLost.sql

20 lines
555 B
MySQL
Raw Permalink Normal View History

2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost`
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