Num Red1 Red2 Red3 Red4 Red5 Red62003002 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多列怎么办啊,各位高手

解决方案 »

  1.   

    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
      

  2.   

    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 reddrop #tab
      

  3.   

    red         Total       
    ----------- ----------- 
    1           2
    3           1
    4           3
    6           2
    7           2
    9           1
    10          3
    13          1
    15          1
    17          1
    19          1
    20          1
    21          2
    23          1
    25          1
    26          2
    27          1
    28          1
    30          1
    31          1
    32          1(21 row(s) affected)
      

  4.   

    Select 
    Red, 
    Count(*) As 出现的次数
    From(
    Select Red2 As Red From History
    Union All
    Select Red3 From History
    Union All 
    Select Red4 From History
    Union All 
    Select Red5 From History
    Union All 
    Select Red6 From History
    ) A
    Group By
    Red
      

  5.   

    好象就這麼種方法,少了一列
    Select 
    Red, 
    Count(*) As 出现的次数
    From(
    Select Red1 As Red From History
    Union All
    Select Red2 As Red From History
    Union All
    Select Red3 From History
    Union All 
    Select Red4 From History
    Union All 
    Select Red5 From History
    Union All 
    Select Red6 From History
    ) A
    Group By
    Red
      

  6.   

    都是牛人啊,搞定了Blue是蓝色球,估计你没玩过双色球吧蓝色就1列,红色的有6列,哈哈一列好搞定撒结贴了
      

  7.   

    create table History 
    (
    Num int,
    Red1 int,
    Red2 int,
    Red3 int,
    Red4 int,
    Red5 int,
    Red6   int)insert into History
    select 2003002 ,4 ,9 ,19 ,20 ,21 ,26 
    union  select  2003003 ,1 ,7, 10 ,23, 28 ,32
    union  select 2003004 ,4 ,6 ,7 ,10 ,13 ,25
    union  select 2003005 ,4 ,6 ,15 ,17 ,30 ,31
    union  select 2003006 ,1 ,3 ,10 ,21 ,26 ,27
    select * from History
    select History.red , count(1)
     from (

    select  Red1 as red from History union  all
    select  Red2 from History union  all 
    select  Red3 from History union  all
    select  Red4 from History union  all 
    select  Red5 from History union  all 
    select  Red6 from History) Historygroup by History.red