gpt4 book ai didi

mysql - 获取两个日期范围之间的行

转载 作者:行者123 更新时间:2023-11-29 07:15:36 25 4
gpt4 key购买 nike

我有一个简单的 SQL 查询,它将搜索两个日期范围之间的匹配行。要搜索的日期格式为“yyyymm”-> 年-月。

我编写了以下查询,但它给了我错误

SELECT *
FROM `my_table`
WHERE added_on BETWEEN EXTRACT( YEAR_MONTH FROM `added_on` )='201606' AND
EXTRACT ( YEAR_MONTH FROM `added_on` )='201706'

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='201606' AND EXTRACT ( YEAR_MONTH FROM `added_on` )='201706' LIMIT 0, 30' at line 1

最佳答案

我认为在这种情况下根本没有必要使用EXTRACT。相反,您可以尝试:

SELECT *
FROM `my_table`
WHERE added_on BETWEEN '20160601' AND '20170630'

关于mysql - 获取两个日期范围之间的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38068088/

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