如何在desc顺序中选择相同的单词

时间:2015-03-30 09:21:56

标签: sql

如何以desc顺序选择列中的相同单词

命名

Apple
Banana
Orange 
Apple 
Cherry
Cherry

欲望输出

Cherry
Cherry
Apple 
Apple

2 个答案:

答案 0 :(得分:1)

如果您只想获得重复的名称,可以使用COUNT / GROUP BY / HAVING

SELECT Name
FROM YOUR_TABLE
GROUP BY Name
HAVING COUNT(Name) > 1
ORDER BY Name DESC

答案 1 :(得分:0)

这可以为您提供所需的输出:

SELECT name FROM table 
WHERE name IN (SELECT name FROM table
               GROUP BY name
               HAVING COUNT(name) > 1)
ORDER BY name DESC