如何求这一列的记录 有图

nettian2006 2009-04-08 07:48:26


这一列是系统生成的不断序列吧,如何取呢
...全文
118 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
yygyogfny 2009-04-08
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 ks_reny 的回复:]
引用 12 楼 mugua604 的回复:
SQL code
--2005
select row_number() over (order by orderid,productid),* from 表名

--2000

select (select count(1) from 表名 where orderid <=a.orderid and productid <a.productid)
from 表名 a

顶。
[/Quote]

qizhengsheng 2009-04-08
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 mugua604 的回复:]
SQL code--2005selectrow_number()over(orderbyorderid,productid),*from表名--2000select(selectcount(1)from表名whereorderid<=a.orderidandproductid<a.productid)from表名 a
[/Quote]

up
npkaida 2009-04-08
  • 打赏
  • 举报
回复
从楼主的图可以判断,该列是有应用程序生成的。
ks_reny 2009-04-08
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 mugua604 的回复:]
SQL code
--2005
select row_number() over (order by orderid,productid),* from 表名

--2000

select (select count(1) from 表名 where orderid<=a.orderid and productid<a.productid)
from 表名 a
[/Quote]
顶。
haidexuanshi 2009-04-08
  • 打赏
  • 举报
回复
上面的都说了,顶一个
ws_hgo 2009-04-08
  • 打赏
  • 举报
回复
create table #EE(OrderID int)
insert #EE
select 10248 union all
select 10248 union all
select 10249 union all
select 10249 union all
select 10250 union all
select 10250 union all
select 10250 union all
select 10251 union all
select 10251 union all
select 10251 union all
select 10252 union all
select 10252

select row_number() over (order by OrderID)rank,OrderID from #EE
rank OrderID
-------------------- -----------
1 10248
2 10248
3 10249
4 10249
5 10250
6 10250
7 10250
8 10251
9 10251
10 10251
11 10252
12 10252
mugua604 2009-04-08
  • 打赏
  • 举报
回复

--2005
select row_number() over (order by orderid,productid),* from 表名

--2000

select (select count(1) from 表名 where orderid<=a.orderid and productid<a.productid)
from 表名 a
csdyyr 2009-04-08
  • 打赏
  • 举报
回复
declare @tb table(OrderID int)
insert @tb
select 10248 union all
select 10248 union all
select 10249 union all
select 10249 union all
select 10250 union all
select 10250 union all
select 10250 union all
select 10251 union all
select 10251 union all
select 10251 union all
select 10252 union all
select 10252

select row_number() over (order by OrderID) AS ' ',OrderID
from @tb
/*
OrderID
-------------------- -----------
1 10248
2 10248
3 10249
4 10249
5 10250
6 10250
7 10250
8 10251
9 10251
10 10251
11 10252
12 10252
*/
Zoezs 2009-04-08
  • 打赏
  • 举报
回复

select row_number() over (order by orderid asc),* from
(select * from TB where....(你需要的数据))T
pt1314917 2009-04-08
  • 打赏
  • 举报
回复

select row_number() over (order by orderid,productid),* from 表名
sdhdy 2009-04-08
  • 打赏
  • 举报
回复
--或者这样,加一自增列,查询完再去掉。
alter table tb add px int identity(1,1)
select * from tb
alter table tb drop column px
sdhdy 2009-04-08
  • 打赏
  • 举报
回复
?
nettian2006 2009-04-08
  • 打赏
  • 举报
回复
用时间表啊?有不用的没?

-SQL 2005可以用 row_number() 取。这也在系统内部自动产生了临时表啊?
sdhdy 2009-04-08
  • 打赏
  • 举报
回复
--或者用临时表
select px=identity(int,1,1),* into #temp from tb

select * from #temp

drop table #temp
liangCK 2009-04-08
  • 打赏
  • 举报
回复
SELECT ID=IDENTITY(INT,1,1),* INTO #T FROM TB

SELECT * FROM #T
sdhdy 2009-04-08
  • 打赏
  • 举报
回复
--SQL 2005可以用 row_number() 取。
nettian2006 2009-04-08
  • 打赏
  • 举报
回复
不是orderid列,是它前面的那个列名是空白的那列
sdhdy 2009-04-08
  • 打赏
  • 举报
回复
--什么意思?猜一个。
select distinct orderid from tb

34,590

社区成员

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

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