SQL如何多表分组统计一起显示

select*from(SELECTqw,COUNT(qw)ASa1FROMmrmxbGROUPBYqwORDERBYa1unionSELECTbw,COUNT(bw)A... select * from (
SELECT qw, COUNT(qw) AS a1 FROM mrmxb GROUP BY qw ORDER BY a1 union
SELECT bw, COUNT(bw) AS a1 FROM mrmxb GROUP BY bw ORDER BY a2 union
SELECT sw, COUNT(sw) AS a1 FROM mrmxb GROUP BY sw ORDER BY a3 union
SELECT gw, COUNT(gw) AS a1 FROM mrmxb GROUP BY gw ORDER BY a4)derivedtbl
展开
 我来答
百度网友2dca20d
2014-12-25 · TA获得超过4036个赞
知道大有可为答主
回答量:2638
采纳率:77%
帮助的人:1026万
展开全部
这样改试一下:
select * from (
SELECT qw, COUNT(qw) AS a1 FROM mrmxb GROUP BY qw union
SELECT bw, COUNT(bw) AS a1 FROM mrmxb GROUP BY bw union
SELECT sw, COUNT(sw) AS a1 FROM mrmxb GROUP BY sw union
SELECT gw, COUNT(gw) AS a1 FROM mrmxb GROUP BY gw ORDER BY 2)derivedtbl

看行不行。
追问
不要order by 就行了 ,其实我是想按列显示 例如 qw,a1,bw,a2,sw,a3,gw,a4 能这样显示吗?
追答
同一行的qw,bw,sw,gw的值一样吗?
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式