数据库结果集排行
SELECT top 10 BOARD_ID,REPLY_CONT,READ_CONTFROM oa_bbs_comment
WHERE BOARD_ID=9
ORDER BY READ_CONT DESC,REPLY_CONT DESC
查询的结果集为:
BOARD_ID REPLY_CONT READ_CONT
9 5 2
9 5 1
9 4 1
我想再添加一列(RANK)作为排名,效果为:
RANK BOARD_ID REPLY_CONT READ_CONT
1 9 5 2
2 9 5 1
3 9 4 1
请问,怎样才能得到并显示排名呢?谢谢您的参与
--------------------编程问答-------------------- 关注! --------------------编程问答-------------------- SELECT top 10 BOARD_ID,REPLY_CONT,READ_CONT
FROM oa_bbs_comment
WHERE BOARD_ID=9
ORDER BY RANK ASC,READ_CONT DESC,REPLY_CONT DESC --------------------编程问答-------------------- 建议
可以不在数据库排行! --------------------编程问答-------------------- sql05用rownumber()
sql2000用 select count() --------------------编程问答--------------------
declare @tb table(BOARD_ID int,REPLY_CONT int,READ_CONT int)
insert into @tb select 9,5,1
insert into @tb select 9,5,2
insert into @tb select 9,4,1
SELECT top 10
orderid=row_number() over(order by REPLY_CONT desc,READ_CONT desc),
BOARD_ID,REPLY_CONT,READ_CONT
FROM @tb
WHERE BOARD_ID=9
orderid BOARD_ID REPLY_CONT READ_CONT
1 9 5 2
2 9 5 1
3 9 4 1 --------------------编程问答-------------------- 思路
通过自己排大小ORDER BY
在添加1到数据行的记录。
补充:.NET技术 , ASP.NET