salix/db/routines/bi/views/v_ventas_contables.sql

24 lines
617 B
SQL

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `bi`.`v_ventas_contables`
AS SELECT `time`.`year` AS `year`,
`time`.`month` AS `month`,
cast(
sum(
`m`.`Cantidad` * `m`.`Preu` * (100 - `m`.`Descuento`) / 100
) AS decimal(10, 0)
) AS `importe`
FROM (
(
(
`vn2008`.`Tickets` `t`
JOIN `bi`.`f_tvc` ON(`t`.`Id_Ticket` = `bi`.`f_tvc`.`Id_Ticket`)
)
JOIN `vn2008`.`Movimientos` `m` ON(`t`.`Id_Ticket` = `m`.`Id_Ticket`)
)
JOIN `vn2008`.`time` ON(`time`.`date` = cast(`t`.`Fecha` AS date))
)
WHERE `t`.`Fecha` >= '2014-01-01'
GROUP BY `time`.`year`,
`time`.`month`