SELECT DATEDIFF(dd, (SELECT date FROM player WHERE
date = (SELECT MAX(date) FROM player WHERE name = 'Deuslegio')
AND name = 'Deuslegio'), CURDATE())
基本上,我要做的就是获取某个玩家名称的最新行记录日期 并从今天的日期获得差异。但根据GoDaddy上的phpMyAdmin,我收到了这个错误:
错误:您的SQL语法出错;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在第1行'CURDATE())'附近
答案 0 :(得分:2)
您在DATEDIFF
功能中使用了三个参数:
1. dd
2. (SELECT DATE FROM player WHERE DATE = (SELECT MAX(DATE) FROM player WHERE NAME = 'Deuslegio') AND NAME = 'Deuslegio')
3. CURDATE()
您只能使用两个。
答案 1 :(得分:0)
您可以大量简化查询。这是您的查询(通过删除dd
:
SELECT DATEDIFF((SELECT date
FROM player
WHERE date = (SELECT MAX(date) FROM player WHERE name = 'Deuslegio'
) AND name = 'Deuslegio'
), CURDATE()
)
以下是等效的:
SELECT DATEDIFF((SELECT date
FROM player
WHERE name = 'Deuslegio'
order by date desc
limit 1
), CURDATE()
)