sql单表查询之分类汇总。
我用"SELECTsb_czlxas类别,wxyh_jbas级别,count(*)AS次数,sum(wx_jinghui)AS经费FROMwxinfoGROUPBYsb_...
我用"SELECT sb_czlx as 类别, wxyh_jb as 级别, count(*) AS 次数, sum(wx_jinghui) AS 经费 FROM wxinfo GROUP BY sb_czlx, wxyh_jb" 得到结果如图,现在想把 维修和保护两类分别汇总(包括次数和经费),然后再总体汇总,请问如何写查询语句?
展开
3个回答
展开全部
用union all合并就OK了
SELECT sb_czlx as 类别, wxyh_jb as 级别, count(*) AS 次数, sum(wx_jinghui) AS 经费 FROM wxinfo GROUP BY sb_czlx, wxyh_jb
union all
SELECT sb_czlx as 类别, null as 级别, count(*) AS 次数, sum(wx_jinghui) AS 经费 FROM wxinfo GROUP BY sb_czlx
SELECT sb_czlx as 类别, wxyh_jb as 级别, count(*) AS 次数, sum(wx_jinghui) AS 经费 FROM wxinfo GROUP BY sb_czlx, wxyh_jb
union all
SELECT sb_czlx as 类别, null as 级别, count(*) AS 次数, sum(wx_jinghui) AS 经费 FROM wxinfo GROUP BY sb_czlx
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SELECT sb_czlx as 类别, count(*) AS 次数, sum(wx_jinghui) AS 经费 FROM wxinfo GROUP BY sb_czlx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
再嵌套一个select ..from
追问
怎么做,请写个完整的语句。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询