解决方案 »
- 怎样解决提交到mysql中的数据,输出后是按照输入的格式输出
- MySQL双向复制有大量的主键重复,请问是什麽原因
- 请教关于数据类型TEXT、MEDIUMTEXT的选择问题
- 关于数据库的实际设计问题问一下
- mysql 修改了文件 但恢复后还是不能用了 谁有好办法没?
- 如何去掉这个锁
- 一个列表插入到数据库的一个表的一个字段里面,一个一行
- 我是初学者,想请教大哥大姐们一个问题?请您给点面子!
- MySQL 4.1,为什么每次用Password加密后的字符串都不一样啊
- 按照时间段查询如何补全不存在的日期的数据
- 用test1用户建了一个表A,再用test2用户去写表A,提示没有权限,问。。
- 大家帮帮看,这组SQL如何分组一次查询,并分组输出?
(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
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
`a1` char(1) default NULL,
`a2` char(1) default NULL,
......
`a29` char(1) default NULL,
`a30` char(1) default NULL,
`time` char(100) default NULL,
`id` int(50) unsigned NOT NULL auto_increment,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;a1--a30中存储的都是数字,1,2,3,4.。。13==但不确定而且不知道最大值。
需要的结果是:
a1到a30每个字段中出现的每个数字的次数和在本表数据条数中的百分比(有100条数据,那么分母就是100)这样够清楚了吧。
From (
Select a1 as n From vote
Union all
Select a2 From vote
Union all
Select a3 From vote
Union all
Select a4 From vote
Union all
Select a5 From vote
Union all
Select a6 From vote
Union all
Select a7 From vote
Union all
Select a8 From vote
Union all
Select a9 From vote
Union all
Select a10 From vote
Union all
Select a11 From vote
Union all
Select a12 From vote
Union all
Select a13 From vote
Union all
Select a14 From vote
Union all
Select a15 From vote
Union all
Select a16 From vote
Union all
Select a17 From vote
Union all
Select a18 From vote
Union all
Select a19 From vote
Union all
Select a20 From vote
Union all
Select a21 From vote
Union all
Select a22 From vote
Union all
Select a23 From vote
Union all
Select a24 From vote
Union all
Select a25 From vote
Union all
Select a26 From vote
Union all
Select a27 From vote
Union all
Select a28 From vote
Union all
Select a29 From vote
Union all
Select a30 From vote
) t
Group by n