?sql

dadihongchang 2008-11-07 05:09:14
no counts
a 10
c 90
d 2
e 100
得到形式?
no counts paixu
e 100 1
c 90 2
a 10 3
d 2 4
...全文
79 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
surpass63 2008-11-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dobear_0922 的回复:]
SQL code--> By dobear_0922(小熊) 2008-11-07 17:11:02
--> 测试数据:@t
declare @t table([no] varchar(1),[counts] int)
insert @t
select 'a',10 union all
select 'c',90 union all
select 'd',2 union all
select 'e',100

select *,paixu=ROW_NUMBER() OVER(order by [counts] desc)
from @t order by [counts] desc

~ …
[/Quote]
jimoshatan 2008-11-08
  • 打赏
  • 举报
回复
没得写了
pengxuan 2008-11-08
  • 打赏
  • 举报
回复

if object_id('t') is not null
drop table t
go
create table t(no varchar(10),counts int)
go
insert into t
select 'a',10 union all
select 'b',90 union all
select 'c',2 union all
select 'd',100
go

select * from t

select no,counts,paixu=identity(int,1,1) into # from t order by counts desc

select * from #
hsie168518 2008-11-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dobear_0922 的回复:]
SQL code--> By dobear_0922(小熊) 2008-11-07 17:11:02
--> 测试数据:@t
declare @t table([no] varchar(1),[counts] int)
insert @t
select 'a',10 union all
select 'c',90 union all
select 'd',2 union all
select 'e',100

select *,paixu=(select count(*) from @t where [counts]>=t.[counts])
from @t t order by [counts] desc

/*
no counts paixu
---- ----------- --------------------
e …
[/Quote]
正解
csdyyr 2008-11-07
  • 打赏
  • 举报
回复
DECLARE @TB TABLE(no VARCHAR(2),  counts INT)
INSERT @TB
SELECT 'a', 10 UNION ALL
SELECT 'c', 90 UNION ALL
SELECT 'd', 2 UNION ALL
SELECT 'e', 100


SELECT *,paixu=IDENTITY(INT,1,1) INTO # FROM @TB ORDER BY counts DESC

SELECT * FROM #

DROP TABLE #
/*
no counts paixu
---- ----------- -----------
e 100 1
c 90 2
a 10 3
d 2 4
*/
dobear_0922 2008-11-07
  • 打赏
  • 举报
回复
--> By dobear_0922(小熊) 2008-11-07 17:11:02
--> 测试数据:@t
declare @t table([no] varchar(1),[counts] int)
insert @t
select 'a',10 union all
select 'c',90 union all
select 'd',2 union all
select 'e',100

select *,paixu=(select count(*) from @t where [counts]>=t.[counts])
from @t t order by [counts] desc

/*
no counts paixu
---- ----------- --------------------
e 100 1
c 90 2
a 10 3
d 2 4

(4 行受影响)
*/
dobear_0922 2008-11-07
  • 打赏
  • 举报
回复
--> By dobear_0922(小熊) 2008-11-07 17:11:02
--> 测试数据:@t
declare @t table([no] varchar(1),[counts] int)
insert @t
select 'a',10 union all
select 'c',90 union all
select 'd',2 union all
select 'e',100

select *,paixu=ROW_NUMBER() OVER(order by [counts] desc)
from @t order by [counts] desc

/*
no counts paixu
---- ----------- --------------------
e 100 1
c 90 2
a 10 3
d 2 4

(4 行受影响)
*/
csdyyr 2008-11-07
  • 打赏
  • 举报
回复


select *,id=identity(int,1,1) into # from tb
dobear_0922 2008-11-07
  • 打赏
  • 举报
回复
Row_Number

34,873

社区成员

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

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