我看过其他问题的建议。添加了背tics,检查我正在比较日期值,但无法使此代码工作。我在这个陈述中做错了什么?
SELECT * from project where project.completed_date >= '2015-01-01' order by customer, projectName
它给了我一个例外
" javax.servlet.ServletException:java.sql.SQLException:未知列' 2015-01-01'在' where子句'"
为什么它将该日期视为列而不是值?
答案 0 :(得分:1)
您应该在日期周围使用单引号(或双引号),而不是反引号。因此查询应如下所示:
SELECT *
FROM project
WHERE project.completed_date >= '2015-01-01'
ORDER BY customer, projectName
答案 1 :(得分:1)
尝试
SELECT *
FROM project
WHERE completed_date >= STR_TO_DATE('2015-01-01', '%Y-%m-%d')
ORDER BY customer, projectName
答案 2 :(得分:0)
您正在比较字符串和日期。重写您的查询,如:
SELECT * from project where project.completed_date >= STR_TO_DATE('2015-01-01','%Y-%m-%d') order by customer, projectName
有关详细信息,请参阅:Converting a date in MySQL from string field