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

20 lines
514 B
MySQL
Raw Permalink Normal View History

2024-08-20 08:06:10 +00:00
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`