在我的表中,我有条目(与datetime数据类型),如:
我需要特定UNIX时间戳之间的结果。当我运行查询时:
Select ifnull(ji.JobID,'') as JobID, ifnull(ji.ReelIndex,'') as ReelIndex, ifnull(ji.FileName,'') as FileName,
ifnull(ji.MediaType,'') as MediaType, ifnull(ji.QCStatus,'') as QCStatus, ifnull(ji.QCComments,'') as QCComments,
ifnull(ji.PackagingStatus,'') as PackagingStatus, ci.Name
from job_info as ji
left join content_info as ci on
ji.ContainerID = ci.ID
where ji.Progress = 100
where ji.ProcessStartTime >= 1449081000
and ji.ProcessEndTime <= 1450549800
order by Name asc, ReelIndex asc
LIMIT 0 , 20
它会抛出错误:
错误代码:1064您的SQL语法出错;查看与您的MySQL服务器版本对应的手册 要使用的语法&#39;其中ji.ProcessStartTime&gt; = 1449081000和 ji.ProcessEndTime&lt; = 1450549800或&#39;在第4行
这可能是什么原因?
答案 0 :(得分:1)
您需要使用WHERE
加倍AND/OR
:
SELECT ifnull(ji.JobID,'') AS JobID,
ifnull(ji.ReelIndex,'') AS ReelIndex,
ifnull(ji.FileName,'') AS FileName,
ifnull(ji.MediaType,'') AS MediaType,
ifnull(ji.QCStatus,'') AS QCStatus,
ifnull(ji.QCComments,'') AS QCComments,
ifnull(ji.PackagingStatus,'') AS PackagingStatus,
ci.Name
FROM job_info AS ji
LEFT JOIN content_info AS ci
ON ji.ContainerID = ci.ID
WHERE ji.Progress = 100
AND ji.ProcessStartTime >= FROM_UNIXTIME(1449081000) -- here
AND ji.ProcessEndTime <= FROM_UNIXTIME(1450549800)
ORDER BY Name ASC, ReelIndex ASC
LIMIT 0, 20;
修改强>
如果您想跳过时间部分并将其设置为00:00:00
CAST
至DATE
:
...
AND CAST(ji.ProcessStartTime AS DATE) >= FROM_UNIXTIME(1449081000)
AND CAST(ji.ProcessEndTime AS DATE) <= FROM_UNIXTIME(1450549800)
另请注意,您需要使用FROM_UNIXTIME
将unix_timestamp转换为datetime。