SELECT FirstId,SecondId
FROM Table
GROUP BY FirstId,SecondId
ORDER BY CASE
WHEN SecondId= 18
THEN 1
ELSE 2
END
答案 0 :(得分:1)
这是你想要的吗?
SELECT FirstId,
(CASE WHEN SUM(CASE WHEN SecondId = 18 THEN 1 ELSE 0 END) > 0
THEN 18 ELSE MAX(SecondId)
END) as SecondId
FROM Table
GROUP BY FirstId
ORDER BY FirstId;