+ -
当前位置:首页 → 问答吧 → sql计算当前记录处于全部记录中的第几名怎么写?asp的

sql计算当前记录处于全部记录中的第几名怎么写?asp的

时间:2011-07-10

来源:互联网

按两个字段以上进行比较,我写的,不过没有成功。请高手帮忙改改代码。谢谢
rs("f_id")是当前记录的ID
f_ordering、f_hits、f_id是排序的字段
select count(*) from 表名 WHERE f_ordering>(select f_ordering from 表名 where f_id= "&rs("f_id")&") and f_hits>(select f_hits from 表名 where f_id= "&rs("f_id")&") and f_id<(select f_id from 表名 where f_id= "&rs("f_id")&")

作者: songbaobao123456789   发布时间: 2011-07-10

SQL code
select rn as 排名
from
(
select *,
(
    select count(*)
        from tb as b 
        where b.f_ordering<a.f_odering 
            or(
                   b.f_ordering=a.f_ordering and b.f_hits < a.f_hits
              ) 
            or
              (
                   b.f_ordering=a.f_ordering and b.f_hits = a.f_hits and b.f_id <=a.f_id
              ) 
            
) as rn
from tb as a
) as t where f_id = 你的f_id

作者: aspwebchh   发布时间: 2011-07-10

不明白呀

作者: songbaobao123456789   发布时间: 2011-07-10