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
