DISTINCT的语法如下:
SELECT DISTINCT "栏位名"
FROM "表格名"
举例来说,若要在以下的表格,Store_Information,找出所有不同的店名时,Store_Information 表格
store_name | Sales | Date |
1 | $1500 | Jan-05-1999 |
2 | $250 | Jan-07-1999 |
1 | $300 | Jan-08-1999 |
3 | $700 | Jan-08-1999 |
我們就鍵入,
SELECT DISTINCT store_name FROM Store_Information
結果:
1
2
3
-----------------------------------------------------------------------------------------------------------
DISTINCT统计重复数据
1 小屋 2
2 2 3
3 4 4
4 33 33
7 1 1
8 1 1
9 33 33
10 9 9
select DISTINCT name,addr,COUNT(*) AS js from cs GROUP BY `name` ORDER BY js
结果:
小屋 2 1
2 3 1
4 4 1
9 9 1
33 33 2
1 1 2
最后一列是统计重复的结果