我正在订购这样的记录集:
SELECT * FROM leaderboards ORDER BY time ASC, percent DESC
假设我有与你有关的记录的id,我怎样才能找到它在记录集中的位置,如上所述
我理解是否只是通过说'时间'来命令我可以
SELECT count from table where time < your_id
但是有两个ORDER BYs让我很困惑
答案 0 :(得分:2)
您可以使用变量来指定计数器:
SELECT *, @ctr := @ctr + 1 AS RowNumber
FROM leaderboards, (SELECT @ctr := 0) c
ORDER BY time ASC, percent DESC
答案 1 :(得分:0)
这样做你想要的吗?
SELECT count(*)
FROM leaderboards lb cross join
(select * from leaderboards where id = MYID) theone
WHERE lb.time < theone.time or
(lb.time = theone.time and lb.percent >= theone.percent);
这假设time, percent
没有重复。