2017-07-10 36 views
0

当查询MYSQL查找当前日期的'current_date'中的记录时,查询日期会返回'No'数据。取而代之的是,它返回为MySQL为日期查询返回空结果

"MySQL returned an empty result set (i.e. zero rows). (Query took 0.0004 sec)" 

试过,下面的查询都没有返回任何记录。

受审SQL查询:

SELECT hash FROM malware_db WHERE current_date like '%2017-07-10%' 

SELECT hash FROM malware_db WHERE date(current_date) like '%2017-07-10%' 
SELECT hash FROM malware_db WHERE date(current_date) between date('2017-07-10 00:00:00') AND date('2017-07-10 23:59:59') 

样品DB的记录组

hash,first_seen,last_seen,current_date,status,treat,trust,name,famil,generic,platform,subplatform,mType,scannerPercent 

9dc1a6770bf57142bbfb9428b3e6213e,2014-06-10 22:01:00,2017-07-02 18:10:00,2017-07-10 23:06:23,MALICIOUS,5,5,Android.Exploit.Lotoor,Lotoor,False,Android,None,None,57.1428565979 

在该结构中, “current_date” 列的Type是 “datetime”。

不确定,这里有什么问题?有什么建议吗?

+1

'date(current_date)= curdate()'应该有效。 –

+1

将'current_date'包裹在坟墓中。如:'\'current_date \''。所以,试试这个:SELECT hash从malware_db WHERE \'current_date \'就像'%2017-07-10% – Mojtaba

+0

@Mojtaba Nope那没有帮助。我得到了“#1064 - 你的SQL语法有错误;检查与你的MySQL服务器版本相对应的手册,在第1行”%2017-07-10%'附近使用正确的语法“ hash FROM malware_db WHERE'current_date' like'%2017-07-10%“ – Arun

回答

1
select hash from malware_db where date(current_date) = date(now()); 
+0

谢谢Raju。这将给我所有的数据,但不是只有'2017-07-10'的数据。 – Arun

1
SELECT hash FROM malware_db WHERE DATE(current_date) = '2017-07-10' 

但它确实听起来像你没有在正确的数据库/表中查找,因为所有这些建议都应该有效。