数据库计算一条记录的名次

有些东西很简单,自己却想不出来。

平时的工作中习惯了把记录排序然后把结果列表排序输出。但是闲的时候我就想,怎么知道某条记录在某种排序方式下面的排位(名次)呢?

在国外一个blog里看到办法的时候,感觉自己真是愚蠢。而在该blogger提出这个问题让大家留言回答的时候,许多人都想的是非常复杂的办法,包括存储过程、临时表。

国内无法正常访问该blog,实际上思想很简单,该条记录的位置就是它前面的记录数加一。其实这不正是名次的定义吗?真是羞愧……这个问题我想了很久,想不到一个合理的办法……

This entry was posted on Thursday, June 26th, 2008 at 8:24 pm and is filed under Database. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 Comment »

Comment by Jicheng
2008-06-27 14:10:45

我也有同样的困惑
我经常想,如果我生在牛顿时代,那么现在就一定没有牛顿定律了,取而代之的就将是继承定律

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)

Please copy the string AsWofR to the field below: