22 lines
586 B
MySQL
22 lines
586 B
MySQL
|
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||
|
SQL SECURITY DEFINER
|
||
|
VIEW `bi`.`v_clientes_jerarquia`
|
||
|
AS SELECT `c`.`id_cliente` AS `Id_Cliente`,
|
||
|
`c`.`cliente` AS `Cliente`,
|
||
|
`t`.`CodigoTrabajador` AS `Comercial`,
|
||
|
`tj`.`CodigoTrabajador` AS `Jefe`
|
||
|
FROM (
|
||
|
(
|
||
|
(
|
||
|
`vn2008`.`Clientes` `c`
|
||
|
JOIN `vn2008`.`Trabajadores` `t` ON(`t`.`Id_Trabajador` = `c`.`Id_Trabajador`)
|
||
|
)
|
||
|
JOIN `vn2008`.`jerarquia` ON(
|
||
|
`vn2008`.`jerarquia`.`worker_id` = `c`.`Id_Trabajador`
|
||
|
)
|
||
|
)
|
||
|
JOIN `vn2008`.`Trabajadores` `tj` ON(
|
||
|
`tj`.`Id_Trabajador` = `vn2008`.`jerarquia`.`boss_id`
|
||
|
)
|
||
|
)
|