gpt4 book ai didi

MySQL : first day of the week and last day of the week not working as desired

转载 作者:行者123 更新时间:2023-11-29 05:57:05 27 4
gpt4 key购买 nike

我有一个名为 stockinstable 和一个 column stock。因为我想在一周的第一天和一周的最后一天之间找到 max(stock)

为此,我使用以下查询

select max(stock) 
from stockins
where date >= '(DATE(NOW()) - INTERVAL (WEEKDAY(DATE(NOW()))) DAY)'
and date <= '(DATE(NOW() + INTERVAL (6 - WEEKDAY(NOW())) DAY))'

但是输出出错了。

如果我运行下面的查询

select max(stock) 
from stockins
where date >= '(DATE(NOW()) - INTERVAL (WEEKDAY(DATE(NOW()))) DAY)'
and date <= '2018-01-28'

然后我得到了想要的输出。

我哪里可能出错了?

最佳答案

只需删除单引号。

select max(stock) from stockins where date >= (DATE(NOW()) - INTERVAL (WEEKDAY(DATE(NOW()))) DAY) and date <= (DATE(NOW() + INTERVAL (6 - WEEKDAY(NOW())) DAY))

关于MySQL : first day of the week and last day of the week not working as desired,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48422063/

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