I'm having trouble with this query im trying to select the row number based on (upvotes - downvotes) in a certain subset of a table , but i need to also reset the @rownum within the same query:
This query works but I need to run two of them. Anyway to combine the set @rownum into one query my attempts have been in vain.
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
This one throws an error:
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