表中不带表示列,但查出的结果中要带标识列

g75510118 2009-06-22 11:19:24
如题,
老师给我们的思路是 例如表中有电话号码这一列
用表连接,连他自己,然后比较这一列,用count来做

求教
...全文
86 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChinaJiaBing 2009-06-22
  • 打赏
  • 举报
回复
如题,
老师给我们的思路是 例如表中有电话号码这一列
用表连接,连他自己,然后比较这一列,用count来做

求教


select *,个数= (select count(*) from 表 where a.字段<b.字段 and a.字段=字段) from 表 a
feixianxxx 2009-06-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wufeng4552 的回复:]
引用楼主 g75510118 的帖子:
如题,
老师给我们的思路是 例如表中有电话号码这一列
用表连接,连他自己,然后比较这一列,用count来做

求教



SQL codeselect *,NO=(select count(*) from tb where tel<=t.tel)from tb t
[/Quote]
水哥 UP
fwacky 2009-06-22
  • 打赏
  • 举报
回复



--1,sql2000
select *,id=identity(int,1,1) into # from tb
select * from #
drop tabel #

---2,sql2005
select*,id=row_number() over (order by getdate()) from tb

fwacky 2009-06-22
  • 打赏
  • 举报
回复

/*****
1,sql2000
select *,id=identity(int,1,1) into # from tb
select * from #
drop tabel #

2,sql2005
select*,id=row_number() over (order by getdate()) from tb
***/

csdyyr 2009-06-22
  • 打赏
  • 举报
回复
--SQL 2005
select *,id=row_number() over (order by getdate())
from tb
--小F-- 2009-06-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wufeng4552 的回复:]
引用楼主 g75510118 的帖子:
如题,
老师给我们的思路是 例如表中有电话号码这一列
用表连接,连他自己,然后比较这一列,用count来做

求教



SQL codeselect *,NO=(select count(*) from tb where tel<=t.tel)from tb t
[/Quote]

支持
水族杰纶 2009-06-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 g75510118 的帖子:]
如题,
老师给我们的思路是 例如表中有电话号码这一列
用表连接,连他自己,然后比较这一列,用count来做

求教
[/Quote]
select *,NO=(select count(*) from tb where tel<=t.tel)from tb t
csdyyr 2009-06-22
  • 打赏
  • 举报
回复
select * from #
csdyyr 2009-06-22
  • 打赏
  • 举报
回复
select *,id=identity(int,1,1) into # from tb

34,873

社区成员

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

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