20 lines
554 B
SQL
20 lines
554 B
SQL
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
SQL SECURITY DEFINER
|
|
VIEW `vn`.`NewView`
|
|
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
|