select rank() over(order by 交款 desc) 名次,部门,交款 from tab;select row_number() over(order by 交款 desc) 名次,部门,交款 from tab;
如果在SQL SERVER: select 名次,* into #tmp from tablename order by 交款 select * from #tmp drop table #tmp // 或用: select 名次=(select count(*) from tablename where a.交款<=交款),* from tablename a 刚学Oracle,以前会SQL SERVER,各位去接分:http://community.csdn.net/Expert/topic/3974/3974332.xml?temp=.7523615
select rownum 名次,部门,交款 from( select 部门,交款 from tab order by 交款 desc )
select rownum 名次,部门,交款 from( select 部门,交款 from tab order by 交款 desc )楼上正解! 注意:使用rownum一定要注意不要和order by冲突,一定要在order by的外一层使用,否则容易出错。
但是如果前两个部门名次一样!如: 名次 部门 交款 1 A 1000 1 B 1000 3 C 600 ... ... ....那又该怎么加啊?那个rownum我也知道!
select rank() over(order by 交款 desc) 名次 ,部门 ,交款 from table 名次 部门 交款 1 A 1000 1 B 1000 3 C 600 ... ... .... select dense_rank() over(order by 交款 desc) 名次 ,部门 ,交款 from table 名次 部门 交款 1 A 1000 1 B 1000 2 C 600 ... ... .... select row_number() over(order by 交款 desc) 名次 ,部门 ,交款 from table 名次 部门 交款 1 A 1000 2 B 1000 3 C 600 ... ... ....
select rownumber 名次 depart 部门 fee 交款 from table order by desc 我是新手,不知道这么写可以吗
from tab;select row_number() over(order by 交款 desc) 名次,部门,交款
from tab;
select 名次,* into #tmp from tablename order by 交款
select * from #tmp
drop table #tmp
//
或用: select 名次=(select count(*) from tablename where a.交款<=交款),*
from tablename a
刚学Oracle,以前会SQL SERVER,各位去接分:http://community.csdn.net/Expert/topic/3974/3974332.xml?temp=.7523615
from(
select 部门,交款
from tab
order by 交款 desc
)
from(
select 部门,交款
from tab
order by 交款 desc
)楼上正解!
注意:使用rownum一定要注意不要和order by冲突,一定要在order by的外一层使用,否则容易出错。
名次 部门 交款
1 A 1000
1 B 1000
3 C 600
... ... ....那又该怎么加啊?那个rownum我也知道!
名次 部门 交款
1 A 1000
1 B 1000
3 C 600
... ... ....
select dense_rank() over(order by 交款 desc) 名次 ,部门 ,交款 from table
名次 部门 交款
1 A 1000
1 B 1000
2 C 600
... ... ....
select row_number() over(order by 交款 desc) 名次 ,部门 ,交款 from table
名次 部门 交款
1 A 1000
2 B 1000
3 C 600
... ... ....
我是新手,不知道这么写可以吗