我有以下简化视图。你可以看到我在同一张表上有多个子查询。有没有办法让它成为一个单一的子查询?就像是:
(select count(*), sum(..), max(..) from XY1 .....) as (Count1, Sum1, Max1),
(select count(*), sum(..), max(..) from XY2 .....) as (Count2, Sum2, Max2),
这是代码:
drop view if exists view_OffersStat;
create view view_OffersStat as
select
o.Id as Offer_Id,
o.Title,
o.Start,
o.Expires,
(select count(*) from Sale as s where s.Merchant_Id=o.Merchant_Id) as Total_Sales,
(select sum(s.Net) from Sale as s where s.Merchant_Id=o.Merchant_Id) as Total_Net,
(select sum(s.Gross)) from Sale as s where s.Merchant_Id=o.Merchant_Id) as Total_Gross,
(select max(s.Gross) from Sale as s where s.Merchant_Id=l.Merchant_Id) as Max_Gross,
from Offer as o;