我有下表:
---------------
Name Tel
John 1234
John 1234
John 1000
Test 9999
如何计算SQL中所有人的不同电话号码?
感知结果:
---------------
Name count
John 2
Test 1
答案 0 :(得分:2)
你可以试试这个。在DISTINCT
函数和COUNT
GROUP BY
SELECT Name,COUNT(DISTINCT Tel)
FROM T
GROUP BY Name
sqlfiddle:http://sqlfiddle.com/#!9/ea45c/4
答案 1 :(得分:1)
SELECT DISTINCT Tel FROM myTable WHERE Name='John'