[英]MySQL Count all rows and unique rows
I am trying to do exactly what the title says, get the total number of records and the number of records that are unique in a certain column. 我正在尝试完全按照标题中的说明进行操作,以获取记录总数和特定列中唯一的记录数。
What I tried so far 到目前为止我尝试过的
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 ?
However none of these brought me pleasant feelings.. How can I do this? 但是这些都不给我带来愉悦的感觉。
I believe that what you need is this 我相信你需要的是
SELECT COUNT(DISTINCT)
So it should be : 因此应该是:
SELECT COUNT(DISTINCT ip) AS visits FROM tracker;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.