CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`workerBusinessDated` AS SELECT `t`.`dated` AS `dated`, `b`.`id` AS `businessFk`, `b`.`workerFk` AS `workerFk` FROM ( `vn`.`time` `t` LEFT JOIN `vn`.`business` `b` ON( `t`.`dated` BETWEEN `b`.`started` AND IFNULL(`b`.`ended`, `util`.`VN_CURDATE`()) ) ) WHERE `t`.`dated` > `util`.`VN_CURDATE`() + INTERVAL -2 year