求一句SQL,有本事的請進

leotan_yang 2004-05-04 11:40:57
name desc
a 222
a 3333
a 2324
b lkjasdlf
b asdf
結果:

name desc idnum
a 222 1
a 3333 2
a 2324 3
b lkjasdlf 1
b asdf 2
誰知道這條sql如何寫?幫忙急?
...全文
55 27 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
realgz 2004-05-04
  • 打赏
  • 举报
回复
那就是按照物理顺序了,严重建议楼主再去复习下关系数据库的基础知识。
重点:行集。
zheninchangjiang 2004-05-04
  • 打赏
  • 举报
回复
那最好的办法就是,在企业管理器中设计那个表,增加一个idnum列,
再打开那个表,手动输入那么几个数字,我就只会这么一点了。进来了出不去:)
leotan_yang 2004-05-04
  • 打赏
  • 举报
回复
select *,(select count(*) from 表名 where name = a.name and desc<=a.desc) as idnum
from 表名 a


錯在desc<=a.desc,他沒看清楚,我不是按這個在排的。第一條就是1,第二條就是1,如此類推。
realgz 2004-05-04
  • 打赏
  • 举报
回复
楼主啊,马可的查询错在哪里?你怎么试的?
leotan_yang 2004-05-04
  • 打赏
  • 举报
回复
to:chludlf(春露)
我這樣就是直話直說,沒什麼的,你不得罪我,我也不會說什麼的!
你的sql與 txlicenhe(马可) 的sql發生同一個錯!


chludlf 2004-05-04
  • 打赏
  • 举报
回复
哈哈,樓主牌氣還滿大的
chludlf 2004-05-04
  • 打赏
  • 举报
回复
select *,(select sum(1) from 表名 where name = a.name and desc<=a.desc) as idnum
from 表名 a order by name , desc

leotan_yang 2004-05-04
  • 打赏
  • 举报
回复
to: chludlf(春露)
你這是什麼意思,我會的就不在這裡問啦,
看你自己說的是什麼話,真是的。要是你不會的你可以不要出聲。
真沒修養!!!!!!!!!
leotan_yang 2004-05-04
  • 打赏
  • 举报
回复
name desc
a 222
a 3333
a 2324
b lkjasdlf
b asdf
結果:

name desc idnum
a 222 1
a 3333 2
a 2324 3
b lkjasdlf 1
b asdf 2
誰知道這條sql如何寫?幫忙急?

沒樓上說得那麼復雜吧!!!再看看清楚
chludlf 2004-05-04
  • 打赏
  • 举报
回复
樓主高明, 自已用一條語句去解吧!
realgz 2004-05-04
  • 打赏
  • 举报
回复
1、表上存在什么约束(允许重复否)?
2、idnum用什么规则生成?如果你告诉我是物理顺序,那建议再看看什么叫集合
leotan_yang 2004-05-04
  • 打赏
  • 举报
回复
沒關係,大家研究
txlicenhe 2004-05-04
  • 打赏
  • 举报
回复
本事不到家,此题对我来说无解。
zheninchangjiang 2004-05-04
  • 打赏
  • 举报
回复
不好意思,那我就不会了。学习!
leotan_yang 2004-05-04
  • 打赏
  • 举报
回复
to: zheninchangjiang(我爱燕子)
我只要一條sql
leotan_yang 2004-05-04
  • 打赏
  • 举报
回复
to: txlicenhe(马可)
你的sql有點問題,你再看清楚題目,謝謝你的回復!!
leotan_yang 2004-05-04
  • 打赏
  • 举报
回复
在最優化的情況下,就是想一條sql語句完成這個功能。
8992026 2004-05-04
  • 打赏
  • 举报
回复
回复人: leotan_yang(Leotan) ( ) 信誉:95 2004-4-19 16:39:42 得分:0



我是求一條sql來實現呀,用這個方法我也會啦。能再想想嗎?
這樣速度會慢的,如果數據量大的話。請再想想




txlicenhe 2004-05-04
  • 打赏
  • 举报
回复
select *,(select count(*) from 表名 where name = a.name and desc<=a.desc) as idnum
from 表名 a

--本事不够,错了不管。
zheninchangjiang 2004-05-04
  • 打赏
  • 举报
回复
select id=identity(int,1,1),* into #t from tablename
select a.name,a.desc,idnum=(select count(*) from #t b where b.name=a.name and b.id<=a.id) from #t a
加载更多回复(7)

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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