Skip to content
Advertisement

How to query previous 8 quarters for quarterly data report using sql server?

I want to query the previous 8 quarters from today’s date.

Example: last quarter from today’s date = ‘2020-09-30’ and last 8 quarter from today’s date is ‘2018-10-01’.

I want the last 8 quarter previous (‘2018-10-01’) mark as Q1 in my query result instead of Q4 since it’s the 4th quarter of the year 2018. Q2 would be the next quarter which is from January-March 2019 and so on, so forth.

Is there a way to count it from the starting date to current date?

My current query:

Advertisement

Answer

I would just use conditional aggregation:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement