[英]MySQL : first day of the week and last day of the week not working as desired
I have a table
named stockins
with a column
stock
. 我有一个名为
stockins
的table
stockins
有一column
stock
。 In that I want to find max(stock)
between first date of the week and last date of the week. 在那我想在一周的第一天和一周的最后一个日期之间找到
max(stock)
。
To do that I am using the following query 为此,我使用以下查询
select max(stock)
from stockins
where date >= '(DATE(NOW()) - INTERVAL (WEEKDAY(DATE(NOW()))) DAY)'
and date <= '(DATE(NOW() + INTERVAL (6 - WEEKDAY(NOW())) DAY))'
But the output is coming wrong. 但是输出错误。
If I run the below query 如果我运行以下查询
select max(stock)
from stockins
where date >= '(DATE(NOW()) - INTERVAL (WEEKDAY(DATE(NOW()))) DAY)'
and date <= '2018-01-28'
Then I am getting the desired output. 然后,我得到所需的输出。
Where I could be going wrong? 我哪里可能出问题了?
只需删除单引号。
select max(stock) from stockins where date >= (DATE(NOW()) - INTERVAL (WEEKDAY(DATE(NOW()))) DAY) and date <= (DATE(NOW() + INTERVAL (6 - WEEKDAY(NOW())) DAY))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.