gpt4 book ai didi

java - SQL:如何获取与表的时间戳字段具有相同月份和年份的条目?

转载 作者:行者123 更新时间:2023-11-29 06:09:53 24 4
gpt4 key购买 nike

我有下表

+--------------------------------------+---------------------+---------------------+----------+-----------------------------+----------+--------+
| 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 [????]

感谢您的帮助。

最佳答案

只需使用:

select *
from yourtable
where month(app_start) = 2 and year(app_start) = 2004

关于java - SQL:如何获取与表的时间戳字段具有相同月份和年份的条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38938071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com