我有下表
+--------------------------------------+---------------------+---------------------+----------+-----------------------------+----------+--------+
| id | app_start | app_end | title | body | location | allDay |
+--------------------------------------+---------------------+---------------------+----------+-----------------------------+----------+--------+
| 52e782d7-8da8-4b27-a17e-d6beb72649e8 | 2004-04-27 10:30:00 | 2005-02-18 11:00:00 | 10 years | Something. | NY,USA | 0 |
| a3e11a10-26d3-407d-83b3-c3cd6cda128f | 2004-02-17 10:30:00 | 2004-02-17 11:00:00 | 12 years | Insert random message here | NY,USA | 0 |
+--------------------------------------+---------------------+---------------------+----------+-----------------------------+----------+--------+
此处app_start
列的类型为timestamp
。如果我想获得特定月份和年份的行,比如2004年第2行(2月)将返回第二行,我会在where
子句中插入什么?
SELECT * FROM table WHERE [????]
感谢您的帮助。
答案 0 :(得分:2)
只需使用month
和year
:
select *
from yourtable
where month(app_start) = 2 and year(app_start) = 2004