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

20 lines
514 B
SQL

CREATE OR REPLACE DEFINER=`vn`@`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`)
)
JOIN `vn`.`operator` `o` ON(
`o`.`workerFk` = `c`.`workerFk`
)
)
WHERE `c`.`created` > `util`.`VN_CURDATE`()
AND `o`.`machineFk` IS NULL
GROUP BY `c`.`workerFk`