Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Question about T-SQL: grouping data by week
Message
 
 
À
24/03/2002 21:17:48
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00636665
Message ID:
00636677
Vues:
19
In this case you still use DATEPART()
Select Acct, Item, DATEPART(week, InvDate) AS week, SUM(QtyShipped)
FROM mytable 
GROUP BY Acct, Item, DATEPART(week, InvDate)
Using SET DATEFIRST you can change the first day of the week.

Syntax

>Hi, Sergey...
>
>Thanks for your answer - unfortunately, I think I may have worded the question incorrectly.
>
>I'm basically trying to collapse shipments down to the week. I can't really explain this without giving an example...
>
>Monday, the 3rd: 10 units shipped
>Friday, the 7th: 11 units shipped
>
>Monday, the 10th, 6 units shipped
>Tuesday, the 11th, 21 units shipped
>Saturday, the 15th, 3 units shipped
>
>I'm trying to write a T-SQL query so that I can produce this result:
>
>Week ending Saturday the 8th: 21 units shipped
>Week ending Saturday the 15th: 30 units shipped
>
>Also, the week ending date for the query could be a Saturday, but could also be another day of the week. And maybe DATEPART is still the answer, though reading BOL about how to use it has me a bit confused.
>
>Thanks,
>Kevin
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform