简体   繁体   English

从mysql获取今天的不同日期

[英]Getting today's distinct date from mysql

I'm trying to select the distinct IPs from all time from today's date, and it returned 39 rows, but it's suppose to be less, since some of the IPs aren't distinct since they visited from before today. 我正在尝试从今天开始的所有时间中选择不同的IP,它返回了39行,但是应该更少了,因为某些IP从今天开始访问以来就没有区别。 What am I doing wrong? 我究竟做错了什么?

SELECT DISTINCT (ip), DATE AS tempDate
FROM  `ipAll` 
HAVING tempDate =  '2015-12-29'
LIMIT 100

You should be using a WHERE condition rather like below. 您应该使用WHERE条件,而不是像下面这样。 Assuming that you have a date type column named tempdate where you store the visited datetime. 假设您有一个名为tempdatedate类型列,用于存储访问的日期时间。

SELECT DISTINCT ip
FROM  `ipAll` 
WHERE tempDate =  CURDATE();

Instead of HAVING clause use WHERE CLAUSE and get rid of the quotes on the table name. 代替HAVING子句,使用WHERE CLAUSE并删除表名上的引号。 HAVING CLAUSE is used when you use GROUP BY clause. 当您使用GROUP BY子句时,将使用HAVING CLAUSE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM