SQL查询同一张表同一字段不同条件的和,就像图上的,统计出优惠金额总和和总金额总和 我的语句是这样 30
SQL查询同一张表同一字段不同条件的和,就像图上的,统计出优惠金额总和和总金额总和我的语句是这样的selecta.name,SUM(a.money),SUM(b.mone...
SQL查询同一张表同一字段不同条件的和,就像图上的,统计出优惠金额总和和总金额总和
我的语句是这样的
select a.name,SUM(a.money),SUM(b.money) from consum a
left join
(select * from consum b where flag =1) b
on
a.name=b.name
group by a.name
就是不对,求原因及正解 展开
我的语句是这样的
select a.name,SUM(a.money),SUM(b.money) from consum a
left join
(select * from consum b where flag =1) b
on
a.name=b.name
group by a.name
就是不对,求原因及正解 展开
1个回答
2015-09-18
展开全部
Select a.name,a.sum1,b.sum2
(select a.name,sum(a.money) sum1 from consum a group by a.name) a
Left join
(select a.name,sum(a.money) sum2 from consum a where flag = 1 group by a.name) b
On a.name =b.name
Order by a.name
(select a.name,sum(a.money) sum1 from consum a group by a.name) a
Left join
(select a.name,sum(a.money) sum2 from consum a where flag = 1 group by a.name) b
On a.name =b.name
Order by a.name
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询