Andreas
Andreas

Reputation: 137

create multiple counts in one SQL query

I would like to get the number of users per airline per end of each month of one year. Sadly I am only able to get the result per one month. Is it somehow possible to get a table with multiple counts per month in such a way that I don't have to do it all one by one?

That's the query I have for one month:

SELECT  
    COUNT (ID) as Counts, 
    AirlineCode   
FROM [liveDB].[dbo].[AppUser]   
WHERE CreateDate<'2016-10-30'
GROUP BY AirlineCode

Thanks a lot Andreas

Upvotes: 0

Views: 50

Answers (1)

S3S
S3S

Reputation: 25112

Just add the month to the select and group by.

SELECT  
    COUNT (ID) as Counts, 
    ,TheMonth = datepart(month,CreateDate)
   , AirlineCode   
FROM [liveDB].[dbo].[AppUser]   
WHERE CreateDate<'2016-10-30'
GROUP BY AirlineCode, datepart(month,CreateDate)

Upvotes: 1

Related Questions