salix/services/db/install/changes/1.2-CHECK/19-personDepartment.sql

21 lines
785 B
MySQL
Raw Normal View History

2019-01-24 13:15:08 +00:00
USE `vn`;
CREATE
OR REPLACE ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `vn`.`personDepartment` AS
SELECT
2019-01-28 08:52:53 +00:00
`p`.`id_trabajador` AS `workerFk`,
2019-01-24 13:15:08 +00:00
`p`.`name` AS `name`,
`p`.`firstname` AS `firstname`,
`d`.`name` AS `department`
FROM
(((`postgresql`.`person` `p`
JOIN `postgresql`.`profile` `pr` ON ((`pr`.`person_id` = `p`.`person_id`)))
LEFT JOIN (`postgresql`.`business` `b`
LEFT JOIN `postgresql`.`business_labour` `bl` ON ((`b`.`business_id` = `bl`.`business_id`))) ON ((`pr`.`profile_id` = `b`.`client_id`)))
JOIN `vn`.`department` `d` ON ((`d`.`id` = `bl`.`department_id`)))
WHERE
(ISNULL(`b`.`date_end`)
OR (`b`.`date_end` > CURDATE()));