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

18 lines
493 B
SQL

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`exchangeInsuranceOut`
AS SELECT `p`.`received` AS `received`,
sum(`p`.`divisa`) AS `divisa`,
sum(`p`.`divisa`) / sum(`p`.`amount`) AS `rate`
FROM (
(
`vn`.`payment` `p`
JOIN `vn`.`bank` `b` ON(`b`.`id` = `p`.`bankFk`)
)
JOIN `vn`.`accountingType` `at2` ON(`at2`.`id` = `b`.`cash`)
)
WHERE `p`.`currencyFk` = 2
AND `at2`.`code` = 'wireTransfer'
AND `p`.`supplierFk` <> 2213
GROUP BY `p`.`received`