处理周数SQL后插入表格

时间:2021-09-06 07:48:39

I have the following table:

我有下表:

Date          Number
-----------------------------
2018-01-01    10
2018-01-04    5
2018-01-10    10
2018-01-20    5
2018-02-01    8
2018-02-03    2
2018-02-28    10

I want to have the following result:

我希望得到以下结果:

WeekNumber     Year      SumOfNumber
-----------------------------------------------
1              2018      15
2              2018      10
3              2018      5
5              2018      10
9              2018      10

Week day Start from Monday to Sunday. The result should be inserted into a Table.

周日从周一到周日开始。结果应该插入表中。

Does anyone have an idea for this?
Thank you

有没有人对此有所了解?谢谢

1 个解决方案

#1


3  

Use ISO_WEEK in DATEPART() function

在DATEPART()函数中使用ISO_WEEK

select 
       DATEPART(ISO_WEEK, date) WeekNumber, year(date) Year, sum(Number) SumOfNumber
from table
group by DATEPART(ISO_WEEK, date),  year(date)

#1


3  

Use ISO_WEEK in DATEPART() function

在DATEPART()函数中使用ISO_WEEK

select 
       DATEPART(ISO_WEEK, date) WeekNumber, year(date) Year, sum(Number) SumOfNumber
from table
group by DATEPART(ISO_WEEK, date),  year(date)