很难的一个sql,想了半个下午:(

laughsmile 2005-06-14 05:12:43
code value
0001 3000
0002 5000
0004 3100
0001 3000
0001 5000
0001 3000
0003 5000
希望以value字段为计数,显示value字段出现的顺序数
name money counts
0001 3000 1
0002 5000 1
0004 3100 1
0001 3000 2
0001 5000 2
0001 3000 3
0003 5000 3
...全文
77 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
laughsmile 2005-06-14
  • 打赏
  • 举报
回复
Thank you, rea1gz,You are so smart,and you will not need to be fake realgz.
appreciate for your help
phantomMan 2005-06-14
  • 打赏
  • 举报
回复
如果表还有一个自增字段,可以达到要求,假如没有,不知道怎么办,或许用临时表加入自增字段也可以实现
rea1gz 2005-06-14
  • 打赏
  • 举报
回复
select identity(int,1,1) as id,* into #t from tablename

select code as name,value as money,
(select count(*) from #t where code=a.code and value=a.value and id<=a.id) as counts
from #t a
order by id

drop table #t


bl_xin 2005-06-14
  • 打赏
  • 举报
回复
这样做有什么意义呢?一次统计出相同个数不行?
huangjianyou 2005-06-14
  • 打赏
  • 举报
回复
SQL还很笨,遇到这样的问题我都会在编写程序时用过程表解决。

^_^

34,593

社区成员

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

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