我正在尝试按顺序对数据进行分组。我有下表:
<provider></provider>
我需要SQL查询来输出以下内容:
id num
-------
1 1
2 1
3 1
4 2
5 1
6 2
7 2
8 4
9 4
10 4
样本数据:
num count(num)
-------------------
1 3
2 1
1 1
2 2
4 3
选择num,count(num) 来自#temp 按编号分组
我需要这个:
select * into #temp
from (
select 1 as id,1 as num union all
select 2,1 union all
select 3,1 union all
select 4,2 union all
select 5,1 union all
select 6,2 union all
select 7,2 union all
select 8,4 union all
select 9,4 union all
select 10,4
) as abc
select * from #temp
实际输出:
num count(num)
-------------------
1 3
2 1
1 1
2 2
4 3