📜  sql order by where 条件 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:33.204000             🧑  作者: Mango

代码示例1
SELECT ProcductCode AS Id, ProductPrice AS Price
FROM Products WITH (NOLOCK)
WHERE ProductCode IN ('efg', 'abc', 'xyz')
ORDER BY (CASE WHEN ProductCode = 'efg' THEN 1
               WHEN ProductCode = 'abc' THEN 2
               WHEN ProductCode = 'xyz' THEN 3
               ELSE 4  -- in case you change the `where`, put them last
          END);