开发者

Select duplicate rows

开发者 https://www.devze.com 2023-03-01 13:43 出处:网络
I have data like this : col1 | -------- |1| |2| |1| |2| |1| |2| |1| |2开发者_如何学C| |1| |2| How can I get like this and order by MAX to Min :

I have data like this :

| col1 |
--------
|  1   |
|  2   |
|  1   |
|  2   |
|  1   |
|  2   |
|  1   |
|  2   开发者_如何学C|
|  1   |
|  2   |

How can I get like this and order by MAX to Min :

| col1 |
--------
|  2   |
|  1   |

I try this :

SELECT col1 , count(col1 ) FROM myTable GROUP BY col1

But I got strange results


If you want to order by the count of occurences of each value:

SELECT col1, count(1) FROM myTable GROUP BY col1 ORDER BY count(1) DESC

If you want to order by the actual value contained in col1

SELECT DISTINCT col1 FROM myTable ORDER BY col1 DESC


You can use the SQL DISTINCT keyword to only show unique results.

SELECT DISTINCT col1 FROM myTable;

You can then order by that column.

SELECT DISTINCT col1 FROM myTable ORDER BY col1 DESC;
0

精彩评论

暂无评论...
验证码 换一张
取 消