mysql 通过周取第一天_如何在mysql中获取日期的一周的第一天?

假设我有2011年1月3日,我想在一周的第一天,也就是星期天,那是2011年1月2日,我该怎么做?

原因是我有此查询:

select

YEAR(date_entered) as year,

date(date_entered) as 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

是的,我意识到起源拼写错误,但是在此之前我就在这里,因此由于太多内部应用程序引用了它,因此我无法对其进行更正。

因此,我按周分组,但我希望以此填充我的图表,所以我不能让所有的周初看起来都像不同的日期。我该如何解决?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值