尝试检索时间戳之间的值时出现错误代码:1064
Error Code : 1064 while trying to retrieve values between timestamps
在我的 table 中,我有条目 (具有日期时间数据类型),例如:
我需要特定 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
它抛出一个错误:
Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
syntax to use near 'where ji.ProcessStartTime >= 1449081000 and
ji.ProcessEndTime <= 1450549800 or' at line 4
这可能是什么原因?
您有双 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 转换为日期时间。
在我的 table 中,我有条目 (具有日期时间数据类型),例如:
我需要特定 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
它抛出一个错误:
Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where ji.ProcessStartTime >= 1449081000 and ji.ProcessEndTime <= 1450549800 or' at line 4
这可能是什么原因?
您有双 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 转换为日期时间。