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

21 lines
574 B
MySQL
Raw Normal View History

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`workerWithoutTractor`
AS SELECT `c`.`workerFk` AS `workerFk`,
`cl`.`name` AS `Trabajador`,
COUNT(DISTINCT `c`.`id`) AS `Colecciones`,
max(`c`.`created`) AS `created`
FROM (
(
`vn`.`collection` `c`
JOIN `vn`.`client` `cl` ON(`cl`.`id` = `c`.`workerFk`)
)
LEFT JOIN `vn`.`machineWorker` `mw` ON(
`mw`.`workerFk` = `c`.`workerFk`
AND `mw`.`inTimed` > `util`.`VN_CURDATE`()
)
)
WHERE `c`.`created` > `util`.`VN_CURDATE`()
AND `mw`.`workerFk` IS NULL
GROUP BY `c`.`workerFk`