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

27 lines
734 B
MySQL
Raw Normal View History

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`newBornSales`
AS SELECT `v`.`importe` AS `amount`,
`v`.`Id_Cliente` AS `clientFk`,
`c`.`salesPersonFk` AS `userFk`,
`v`.`fecha` AS `dated`,
`cn`.`firstShipped` AS `firstShipped`
FROM (
(
(
(
`bs`.`clientNewBorn` `cn`
JOIN `bs`.`ventas` `v` ON(
`cn`.`firstShipped` + INTERVAL 1 year > `v`.`fecha`
AND `v`.`Id_Cliente` = `cn`.`clientFk`
)
)
JOIN `vn`.`client` `c` ON(`c`.`id` = `v`.`Id_Cliente`)
)
JOIN `account`.`user` `u` ON(`u`.`id` = `c`.`salesPersonFk`)
)
JOIN `account`.`role` `r` ON(`r`.`id` = `u`.`role`)
)
WHERE `r`.`name` = 'salesPerson'
AND `u`.`name` NOT IN ('ismaelalcolea', 'ruben')