双重分组

时间:2011-09-07 16:52:30

标签: sql-server

someid    somestring   SomeValue
  1        Hello          value1
  1        Hello          value2
  1        Blah           value3
  2        World          value4
  2        TestA          value5
  2        TestB          value6
  1        Hello          value7       
  1        World          value8
  1        Blah           value9 
  2        TestB          value10
  2        TestB          value11 
  2        TestB          value12

我需要结果集像这样

someid    somestring    Count(SomeValue)
  1        Hello          3
  1        Blah           2
  2        World          2
  2        TestA          1
  2        TestB          4

有人可以帮忙。

感谢。

2 个答案:

答案 0 :(得分:2)

select someid,something,count(*)
from table
group by someid,something

答案 1 :(得分:0)

试试这个:

select 
    someid,
    somestring,
    count(*) 
from 
    myTable 
group by 
    someid,
    somestring