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 展开
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 展开
1个回答
展开全部
这样改试一下:
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
看行不行。
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的值一样吗?
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询