在这些查询中
SELECT MIN(age)
FROM ages
WHERE id = 5 AND birth = 12;
SELECT MAX(age)
FROM ages
WHERE id = 5 AND birth = 65;
是否可以将它们合并到一个查询中,只在birth
?
答案 0 :(得分:4)
使用条件聚合。
SELECT MIN(CASE WHEN birth = 12 THEN age END)
,MAX(CASE WHEN birth = 65 THEN age END)
FROM ages
WHERE id = 5