我的table
名为stockins
,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'
然后我得到了所需的输出。
我可能会出错?
答案 0 :(得分:2)
只需删除单引号即可。
select max(stock) from stockins where date >= (DATE(NOW()) - INTERVAL (WEEKDAY(DATE(NOW()))) DAY) and date <= (DATE(NOW() + INTERVAL (6 - WEEKDAY(NOW())) DAY))