我有以下查询可以正常工作并检索正确的值。
select col1,sum(s1tot+s2tot-s3tot) as 'value'
from mtable1 maintable1
left outer join
(select sum(s1*t1) s1tot from subtable1
where
period <200
) as t1 on maintable1.id=t1.id
left outer join
(select sum(s2*t2) s2tot from subtable2
period <200) as t2 on maintable1.id=t2.id
left outer join
(select sum(s3*t3) s3tot from subtable3
period <200
) as t3 on maintable1.id=t3.id
where
---
group by
having sum(s1tot+s2tot-s3tot) <> 0
我希望获得要分割价值的结果,按期间的价值。我需要在每个子查询中包含句点,并应在外部/顶部查询中检索
select col1,sum(s1tot+s2tot-s3tot) as 'value',period
from mtable1 maintable1
left outer join
(select sum(s1*t1),period s1tot from subtable1
where
period <200
group by period
) as t1 on maintable1.id=t1.id
left outer join
(select sum(s2*t2) s2tot,period from subtable2
period <200
group by period) as t2 on maintable1.id=t2.id
left outer join
(select sum(s3*t3) s3tot,period from subtable3
period <200
group by period
) as t3 on maintable1.id=t3.id
where
---
group by
having sum(s1tot+s2tot-s3tot) <> 0