MySQL计算所有行和唯一行

时间:2014-09-24 23:35:25

标签: mysql

我正在努力完成标题所说的内容,获取记录总数和特定列中唯一的记录数。

到目前为止我尝试了什么

SELECT COUNT(ip) AS visits, ip FROM tracker WHERE time BETWEEN ? AND ? GROUP BY ip

SELECT DISTINCT COUNT(ip) AS visits, ip FROM tracker WHERE time BETWEEN ? AND ?

SELECT DCOUNT(ip) AS visits, DISTINCT(ip) AS `unique` FROM tracker WHERE time BETWEEN ? AND ?

然而,这些都没有给我带来愉快的感受..我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

我相信你需要的是这个

SELECT COUNT(DISTINCT)

所以它应该是:

SELECT COUNT(DISTINCT ip) AS visits FROM tracker;