如何寫查詢語句實現把排序查詢後的結果編號呢。

fxjpost 2003-10-15 08:38:33
如 select id=(),a,b,sum(c) c from table
group by a,b
order by c
結果:id a b c
1 c b 2
2 d e 3
3 f g 5
4 5 4 4
5 f 4 6
.
.
.
n
...全文
76 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yujohny 2003-10-15
  • 打赏
  • 举报
回复
哦,回答时候还没看到你补充
你就要求C必须是主键,按马可的方法
yujohny 2003-10-15
  • 打赏
  • 举报
回复
select identity(int,1,1) id,a,b,sum(c) c into #a from [table]
group by a,b order by c

select * from #a
txlicenhe 2003-10-15
  • 打赏
  • 举报
回复
除非你有关键字,比如是c

select id=(Select sum(1) from table where c<= aa.c),a,b,sum(c) c from table aa
group by a,b
order by c

pengdali 2003-10-15
  • 打赏
  • 举报
回复
select IDENTITY(int, 1,1) a,b,sum(c) c into #s from [table] group by a,b order by c
select * from #s
fxjpost 2003-10-15
  • 打赏
  • 举报
回复
補充:
注:不要用到臨時表的方法,就用查詢語句有沒有辦法

34,875

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧