+ -
当前位置:首页 → 问答吧 → 求一mysql语句,题目如下:

求一mysql语句,题目如下:

时间:2011-07-05

来源:互联网

求一mysql语句,题目如下: 
  字段a1,a2,a3.....a30每个字段存储着一个数字,不如1,6,7,14等等。。。但是不知他的最大值是多少。
  现求输出a1到a30没个字段下的每个数字出现的次数和百分比的mysql语句。。。。测试成功后马上给分!!在线等。。。

作者: elvaone   发布时间: 2011-07-05

你是每行统计还是N行一起统计??

作者: shine333   发布时间: 2011-07-05

select a1,count(*),count(*)/
(select count(*) from 
(select a1 from tt
union
select a2 from tt
...
union
select a30 from tt) a)

 from (
select a1 from tt
union
select a2 from tt
...
union
select a30 from tt) a
group by a1

作者: WWWWA   发布时间: 2011-07-05

貌似是union all吧....

作者: shine333   发布时间: 2011-07-05

将上述UNION->UNION ALL

作者: WWWWA   发布时间: 2011-07-05

是对所有行的统计。。。。谢谢
引用 1 楼 shine333 的回复:

你是每行统计还是N行一起统计??

作者: elvaone   发布时间: 2011-07-05

相关阅读 更多

热门下载

更多