Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select with count group by every week
Message
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
SQL Select with count group by every week
Miscellaneous
Thread ID:
01687852
Message ID:
01687852
Views:
35
Hi,

I am working on a report (in VFP 9) but the report is based on data in the MS SQL Server. This is why I put this question in the MS SQL Server Forum.

The SQL Select needs to Count a number of records for various condition (see an example below). But what I find challenging is how to specify that the Group By should be on the Monday of every week.

Here is an example:
select [Monday_Of_Each_Week], Count(TableName.Deleted = 'D') as DEL_RECS, Count(TableName.Status = 'I' as STAT1_RECS from TableName 
group by [Monday_Of_Each_Week]
The Monday of each week would be as follows:
The first Monday of 2024 is 01/01/2024, 2nd Monday is 01/08/2024, and so on. Basically the program should select the first week (01/01/2024) where Monday falls on the year. For example, next year (2025), the first week will be the week of 01/06/2025 (because the first Monday in the year is 01/06/2025).

UPDATE. I am updating the SQL Select above because I need to show the count of records for each week (52 weeks in the year). Therefore, the SQL Select should select 52 records.

Any suggestions?

TIA.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Next
Reply
Map
View

Click here to load this message in the networking platform