Oracle:如何在单个查询中进行 GROUP 和 ORDER
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19698798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle : How to GROUP and ORDER in a single Query
提问by Wibowo Margito
There is a table : FRUIT, the content :
有一个表:FRUIT,内容:
NAME
------
Banana
Orange
Orange
Apple
Banana
Apple
Apple
Apple
I want result like this (Grouped and Ordered):
我想要这样的结果(分组和排序):
NAME
----
Apple
Banana
Orange
I created a query :
我创建了一个查询:
SELECT NAME
FROM FRUIT
ORDER BY NAME
GROUP BY NAME
I think it will run weel in MySql or Foxpro. But not in Oracle. How do I should the query like ? Thanks
我认为它会在 MySql 或 Foxpro 中运行。但不是在 Oracle 中。我应该如何查询?谢谢
回答by NoChance
Please try this:
请试试这个:
SELECT NAME
FROM FRUIT
GROUP BY NAME
ORDER BY NAME
You could then use distinct if to prevent duplicates.
然后您可以使用 distinct if 来防止重复。
回答by Aditya Kakirde
YOu can try this as well since you need only a single column to be displayed -
你也可以试试这个,因为你只需要显示一列 -
SELECT DISTINCT NAME
FROM FRUIT
ORDER BY NAME;
回答by Vijay
try it out
试试看
SELECT DISTINCT NAME FROM FRUIT ORDER BY NAME;
this query returns unique NAME with order by NAME..
此查询返回唯一的 NAME,按 NAME 排序。