日期:2014-05-19  浏览次数:20424 次

查询一个数字在各列中出现的次数
Num Red1 Red2 Red3 Red4 Red5 Red6

2003002 4 9 19 20 21 26
2003003 1 7 10 23 28 32
2003004 4 6 7 10 13 25
2003005 4 6 15 17 30 31
2003006 1 3 10 21 26 27
是双色球的期号和红色球出现情况
如何查询各个数字出现的次数(在各列中出现的总和)

对于篮球就一列,本人用的是Select   Distinct   Blue,Count(*)   From   History   Group   By   Blue

多列怎么办啊,各位高手

------解决方案--------------------
select red,Count(1) as Total
from (
select Red1 as Red from tabRed union all
select Red2 from tabRed union all
select Red3 from tabRed union all
select Red4 from tabRed union all
select Red5 from tabRed union all
select Red6 from tabRed )a
group by Red
------解决方案--------------------
select red1 as red into #tab from History
select red2 into #tab from History
....
....
select red6 into #tab from History

Select Distinct red,Count(*) From History Group By red

drop #tab