以下查詢根據用戶投了多少次來計票...我想知道特定用戶隊列中的#號。反轉分組查詢的序列號
SELECT @s:[email protected]+1 serial_number, user_id, COUNT(slug_owner) as cnt
FROM `votes_queue`,(SELECT @s:= 0) AS s
GROUP BY slug_owner
ORDER BY cnt DESC
serial_number | user_id | cnt
3 | 19 | 8
2 | 14 | 4
1 | 13 | 2
從本質上講,我需要的數字在SERIAL_NUMBER列被扭轉,所以我可以告訴大家,用戶13是一個基於投票#3 ..
謝謝。這真的很有幫助! – Ando