我在尝试根据表的某个子集中的(upvotes-downvotes)选择行号时遇到了这个查询问题,但是我还需要在同一查询中重置@rownum:
该查询有效,但我需要运行其中两个。无论如何将集合@rownum组合成一个查询,我的尝试都是徒劳的。
SET @rownum = 0;
SELECT rank
FROM (SELECT *, @rownum:=@rownum + 1 AS
rank FROM Cars where Auto_SET = 'BMW'
order by (upvotes-downvotes) DESC) d
WHERE ID = 391802
这引发了一个错误:
SELECT rank
FROM (SELECT *, @rownum:=@rownum + 1 AS
rank FROM Cars where Auto_SET = 'BMW' ,
(SELECT @rownum:=0) r order by
(upvotes-downvotes) DESC) d
WHERE ID = 391913
最佳答案
cross-join
应该和select from table_name
一样
SELECT rank
FROM (
SELECT *,
@rownum:=@rownum + 1 AS rank
FROM Cars ,(SELECT @rownum:=0) r
where Auto_SET = 'BMW'
order by
(upvotes-downvotes) DESC
) d
WHERE ID = 391913
关于php - mysql选择行号查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29115833/