查询第一行选择

时间:2013-06-18 02:05:20

标签: sql

我正在尝试构建一个查询,它将返回所有行但我选择的第一行。

实施例: -

ID     Type       Name
1      Fruit      Apple
2      Fruit      Orange
3      Veg        Broccoli
4      Fruit      Banana
5      Fruit      Grape
6      Fruit      Kiwi

现在,查询应返回水果列表,但香蕉在顶部。结果应该是

Banana
Apple
Grape
Kiwi
Orange

谢谢!

1 个答案:

答案 0 :(得分:2)

你的意思是这样吗?

select name
from t
where type = 'Fruit'
order by (case when name = 'Banana' then 1 else 0 end) desc, name
相关问题