我的这张表有以下记录:
id(int/11) date(varchar/255)
0 2014-10-14 01:32:07 +0000
1 2014-11-09 12:45:09 +0000
2 2014-12-23 08:21:10 +0000
3 2014-12-24 05:19:55 +0000
我所要做的就是让值更接近我发送的某个日期来分析下面的sql是语法:
SELECT * FROM records ORDER BY ABS('2014-10-14 01:20:55 +0000' - value) WHERE status = '1' LIMIT 1
在这种情况下,语法会返回 ID 0 ,但是我收到以下错误:
near "00": syntax error
我的语法有什么问题?
答案 0 :(得分:3)
您已重新排序ORDER BY
和WHERE
条款:ORDER BY
需要在ORDER BY
之后:
SELECT *
FROM records
WHERE status = '1'
ORDER BY ABS('2014-10-14 01:20:55 +0000' - value)
LIMIT 1