27 lines
732 B
SQL
27 lines
732 B
SQL
CREATE OR REPLACE DEFINER=`vn`@`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')
|