各種可能的答案中提出了一種比較用戶名的:
EXPLAIN SELECT aa.userId, aa.pending
FROM writerdata_tb AS aa
INNER JOIN writerdata_tb AS bb
ON aa.userId = bb.userId
WHERE aa.pending >= bb.pending
ORDER BY aa.pending ASC
LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE aa ALL PRIMARY NULL NULL NULL 4 Using temporary; Using filesort
1 SIMPLE bb ALL PRIMARY NULL NULL NULL 4 Using where; Using join buffer (Block Nested Loop)
EXPLAIN SELECT userId, pending
FROM writerdata_tb
WHERE pending = (
SELECT MIN(pending)
FROM writerdata_tb
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY writerdata_tb ALL NULL NULL NULL NULL 4 Using where
2 SUBQUERY writerdata_tb ALL NULL NULL NULL NULL 4 NULL
EXPLAIN SELECT userId, pending
FROM writerdata_tb
ORDER BY pending ASC
LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE writerdata_tb ALL NULL NULL NULL NULL 4 Using filesort
EXPLAIN SELECT t.userId
FROM writerdata_tb AS t
GROUP BY (
t.userId
)
ORDER BY SUM(pending) ASC
LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t index PRIMARY PRIMARY 4 NULL 4 Using temporary; Using filesort
'ORDER BY未決ASC',比限1 – Terminus
我thinl你可以有多個,其實,不是嗎? –
如果有2位用戶0等待處理,會發生什麼情況?選擇全部還是隻有一個? –