1

MSSQL --

I'm looking to change my data from

OrderDate      Amt
2012-03-05     1
2012-03-06     6
2012-03-06     7
2012-03-07     8
2012-03-08     1
2012-03-08     1

I would like it to list what the start of the week date was, e.g. 2012-01-01 (assume this is sunday) and group all amounts for the week into that date..

How is this possible in SQL?

Thanks James.

4

1 に答える 1

3
  Select DateAdd(D,1-DatePart(Dw,OrderDate),OrderDate) OrderStartOfWeekDate,
         Sum(Amt) TotalAmt
    From Tbl
Group by DateAdd(D,1-DatePart(Dw,OrderDate),OrderDate);
于 2012-10-26T09:15:02.130 に答える