Last active
March 9, 2022 05:02
-
-
Save limingxinleo/d1a267a73c83d9c35d6c06a723ff3b7c to your computer and use it in GitHub Desktop.
Revisions
-
limingxinleo revised this gist
Mar 9, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # reply 表中,以 reply 分组,并查询每个分组 id 最小的前 2 条 SELECT r.* FROM reply r WHERE r.reply_id IN (1, 2) AND 2 >= ( -
limingxinleo created this gist
Mar 9, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ # reply 表中,以 reply 分组,并查询每个分组 id 最小的前 2 条 EXPLAIN SELECT r.* FROM reply r WHERE r.reply_id IN (1, 2) AND 2 >= ( SELECT COUNT(*) FROM reply WHERE reply_id = r.reply_id AND id <= r.id ) ORDER BY r.reply_id, id;