gpt4 book ai didi

php - 如何检查给定日期是否存在于表中?

转载 作者:行者123 更新时间:2023-11-29 21:06:56 26 4
gpt4 key购买 nike

在我的数据库表中包含

id  Start_date End_date      plans
-- --------- ---------- --------
1 0000-00-00 2015-12-31 classic
2 2016-01-01 0000-00-00 Mini

如果我给 Start_date ="2016-02-15"End_date ="2016-04-30" 那么我的输出应该是“2 2016-01-01 0000-00-00 Mini

in case if i give Start_date ="2015-06-01" End_date ="2016-04-30"
then my output should be
1 0000-00-00 2015-12-31 classic and 2 2016-01-01 0000-00-00 Mini
previously my query was
SELECT * FROM plantb WHERE CusID='1' AND AccID='1001' AND SerID='0123456789' AND ( Start_date BETWEEN '2015-06-01' AND '2016-04-30' ) OR ( End_date BETWEEN '2015-06-01' and '2016-04-30') ORDER BY `Start` ASC

最佳答案

我认为您只是想在开始日期结束日期之前让计划现在有效或无效。

试试这个

SELECT * 
FROM plantb
WHERE CusID='1'
AND AccID='1001'
AND SerID='0123456789'
AND CURDATE() BETWEEN Start and End
ORDER BY `Start` ASC

关于php - 如何检查给定日期是否存在于表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36736434/

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