我有张表,如下图,我想以datetime排序,获得每天出现过几个ip地址。
我用下面这段的话,只能取出总数,不是个数
$data['num_ip'] = Db::name("visitors")->where($where)->field("count(ip) as count,datetime")->group("datetime")->select();
,
count(distinct ip)
###SELECT COUNT(DISTINCT `ip`), `datetime`
FROM [TABLE_NAME]
GROUP BY `datetime`
ORDER BY `datetime` ASC;
###这得嵌套查询了吧,第一层按日期,IP去重,第二层再像你现在这样
select count(ip) as count,datetime from
(
select ip,datetime from table_name group by ip,datetime
)as a
group by datetime
###count group by 或 count(distinct)