假设我有一个日期2011-01-03,我想要获取这一周的第一天,也就是星期天即2011-01-02,我该怎么做?
原因是我有以下查询:
select
YEAR(date_entered) as year,
date(date_entered) as week, <-------This is what I want to change to select the first day of the week.
SUM(1) as total_ncrs,
SUM(case when orgin = picked_up_at then 1 else 0 end) as ncrs_caught_at_station
from sugarcrm2.ncr_ncr
where
sugarcrm2.ncr_ncr.date_entered > date('2011-01-01')
and orgin in(
'Silkscreen',
'Brake',
'Assembly',
'Welding',
'Machining',
'2000W Laser',
'Paint Booth 1',
'Paint Prep',
'Packaging',
'PEM',
'Deburr',
'Laser ',
'Paint Booth 2',
'Toolpath'
)
and date_entered is not null
and orgin is not null
AND(grading = 'Minor' or grading = 'Major')
and week(date_entered) > week(current_timestamp) -20
group by year, week(date_entered)
order by year asc, week asc
是的,我知道 origin 的拼写错误,但在我来之前它就已经存在了,所以我不能更正它,因为太多的内部应用程序引用了它。
因此,我按周分组,但我希望这可以填充我的图表,所以我不能让所有开头的周看起来像不同的日期。我该怎么解决这个问题?
DATE_ADD(mydate, INTERVAL(6 -WEEKDAY(mydate)) DAY)
。 - KailiC