0

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

6
  • Your current query is grouping by the airlinecode - not by passenger. Add some sample data, and your table structure. Use the following as a guide: spaghettidba.com/2015/04/24/… Commented Sep 1, 2017 at 17:44
  • 1
    mysql or sql-server ???? is not the same Commented Sep 1, 2017 at 17:49
  • 1
    @scaisEdge I think Stack Overflow's auto-tagger is really bad at these things. Commented Sep 1, 2017 at 17:56
  • @tadman I agree with you .. tags are always added unnecessarily Commented Sep 1, 2017 at 17:57
  • 1
    @scaisEdge Other hypothesis is people think it's the "Mycrosoft SQL Server". Commented Sep 1, 2017 at 17:59

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.