SELECT id FROM article
WHERE id IN (SELECT CASE WHEN SIGN(id - 3) > 0 THEN MIN(id) WHEN SIGN(id - 3) < 0 THEN MAX(id) END AS id
FROM article WHERE id <> 3 GROUP BY SIGN(id - 3) ORDER BY SIGN(id - 3)) ORDER BY id ASC;
article : 表名
3: 当前ID
WHERE id IN (SELECT CASE WHEN SIGN(id - 3) > 0 THEN MIN(id) WHEN SIGN(id - 3) < 0 THEN MAX(id) END AS id
FROM article WHERE id <> 3 GROUP BY SIGN(id - 3) ORDER BY SIGN(id - 3)) ORDER BY id ASC;
article : 表名
3: 当前ID
本文介绍了一种复杂的SQL查询方法,通过使用CASE WHEN、GROUP BY及ORDER BY等子句组合实现对特定ID的高级筛选。该查询从article表中选取ID,并通过条件判断确保返回的ID满足与指定ID(本例中为3)的关系要求。

被折叠的 条评论
为什么被折叠?



