我有一个餐桌工厂 当我选择记录时,返回以下结果: -
SELECT PLANT_NAME FROM PLANT
Plant_Name
-----------
Chicago 65th
-----------
Clearfield
-----------
Lithonia
-----------
Los Angeles
-----------
North Bergen
-----------
Zellwood
-----------
Olathe
-----------
Archerfield
-----------
Epping
-----------
我编写以下查询以显示工厂名称" Zellwood"在倒数第二和" Archerfield"在最后一排。查询是
select Plant_Name from plant order by case Plant_Name
when 'Zellwood' then 1
when 'Archerfield' then 2
end
但它没有订购其余的记录。请给我建议我如何按升序订购其余的记录。
答案 0 :(得分:2)
使用ORDER BY
中的第二个键:
select Plant_Name
from plant
order by (case Plant_Name
when 'Zellwood' then 1
when 'Archerfield' then 2
end),
Plant_Name;
答案 1 :(得分:0)
查询
select ColumnName
from Tablename
order by (case Column Name when 'value' then 1 when 'value' then 2 end), Column Name);