【发布时间】:2011-10-20 02:51:28
【问题描述】:
假设我有 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 拼写错误,但它在我之前就在这里,所以我无法更正它,因为太多内部应用程序引用它。
所以,我按周分组,但我希望它填充我的图表,所以我不能让所有周的开始看起来像不同的日期。我该如何解决这个问题?
【问题讨论】: