我有一个时间戳字段[SubmissionDate],默认为current_timestamp,我想知道如何以这样的方式查询我的数据库,例如我只显示在某个年份和月份提交的所有条目? 类似的东西:
SELECT * FROM DNA_entrys
WHERE `SubmissionDate`.month = February
AND `SubmissionDate`.year = 2004
应该是一个基本的操作,但我找不到快速的答案
答案 0 :(得分:1)
这有用吗?
SELECT * FROM DNA_entrys
WHERE MONTH(SubmissionDate) = 2
AND YEAR(SubmissionDate) = 2004
答案 1 :(得分:1)
SELECT * FROM DNA_entrys
WHERE month(`SubmissionDate`) = 2
AND year(`SubmissionDate`) = 2004
我建议:
SELECT * FROM DNA_entrys
WHERE `SubmissionDate` between '2004-02-01' and ('2004-03-01' - INTERVAL 1 SECOND)
后者允许使用索引,如果您对该字段建立索引,则会使查询更快。