我有这个工作查询
Sum(`sales`.`quantity`) AS totquantity,
`transactions`.`price` AS price,
Sum(`sales`.`quantity`) * `transactions`.`price` AS grantot
from (`sales` join `transactions` on((`transactions`.`idtransaction` = `sales`.`idtransaction`)))
where ((`sales`.`createon` > '01/01/2017') and (`sales`.`createon` < 'now()'))
group by `sales`.`idtransaction`
但是咨询创建这个视图会很有用
select `products`.`idproduct` AS `idproduct`,`transactions`.`idtransaction` AS
`idtransaction`,`transactions`.`idline` AS `idline`,
`products`.`name` AS `name`,`products`.`code` AS `code`,`transactions`.`price` AS `price`,`sales`.`quantity` AS `quantity`,`sales`.`createon` AS `createon`
from (`sales` left join (`transactions` left join `products` on((`products`.`idproduct` = `transactions`.`idproduct`))) on((`transactions`.`idtransaction` = `sales`.`idtransaction`)))
并对视图进行查询
select * from myview where `sales`.`createon` > '01/01/2017' and `sales`.`createon` < 'now()'
现在我的问题是两个结果是一样的吗?
thx提前
您的原始查询使用两个表和完整联接。
但是,视图已经有三个表和左连接。
这足以得出结论,不能保证它们一般会产生相同的结果。
您可以提供更精确的输入以获得更精确的答案。