1
如何在結果在這個SQL使用@row_number狀的位置排:在結果中獲取行位置?
SELECT s.*,
s2.priority AS `priority`,
@row_number := @row_number := @row_number + 1 AS `top`
FROM (SELECT @row_number := 0) init, `server` s
LEFT JOIN servers_services ss ON (s.id = ss.server_id)
LEFT JOIN service s2 ON (s2.id = ss.service_id)
WHERE s.is_banned = 0
ORDER BY ss.service_id IS NULL, priority DESC
@row_number取值爲{1,12,89 ...}爲什麼呢?
'@row_number:= @row_number:= @row_number + 1'>'@row_number := @row_number + 1' – RubahMalam
@RubahMalam,你的例子打印「0」作爲頂部 –
實際上,你的查詢應該有效,除非你有另一個更長的查詢比這個。 – RubahMalam