【发布时间】:2019-03-15 20:11:48
【问题描述】:
假设有这样的表格
domain | city | number
-------------|-----------|-------
example.com | rome | 11111 <--,
example1.com | rome | 11111 |_ this two should be counted as 1
example2.com | rome | 11111 |
example.com | rome | 11111 <--'
example.com | amsterdam | 11111
example2.com | rome | 22222
example.com | uk | 22222
example.com | amsterdam | 22222 <--._ this two should be counted as 1
example.com | amsterdam | 22222 <--'
我想输出类似以下结果11111, total = 4 和22222, total = 3
到目前为止,我有这个查询,但当然不能正常工作! :(
SELECT number, COUNT(number) as total FROM table GROUP BY city, domain
【问题讨论】:
-
关闭试试
COUNT(DISTINCT number) -
你的主键是什么?