2011-09-07[sqlserver投票統計查詢問題]

 create table tb(ID int,polls int,namevarchar(10))

insert into tbvalues(1 ,2 ,'張三')

insert into tbvalues(2 ,9 ,'李四')

insert into tbvalues(3 ,0 ,'王五')

insert into tbvalues(4 ,2 ,'趙六')

insert into tbvalues(5 ,2 ,'周七')

insert into tbvalues(6 ,8 ,'周潤發')

insert into tbvalues(7 ,9 ,'張國榮')

go

 

select * , 排名= (selectcount(distinct polls)from tbwhere polls>= t.polls)from tb t orderby 排名

 

drop table tb

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章