Interview Query

Departmental Spend By Quarter

Start Timer

0:00:00

Upvote
13
Downvote
Save question
Mark as completed
View comments (14)
Next question

Suppose we have a table of transactions happened during 2023, with each transaction belonging to different departments within a company. We want to calculate the total spend for IT, HR, and Marketing, and also have a total for Other departments, grouped by fiscal quarters.

Write a query to display this result.

Note: Display only quarters where at least one transaction occurred. Quarter names should be Q1,Q2,Q3 and Q4. Q1 is from January to March

Example:

Input:

transactions table

Column Type
transaction_id INTEGER
department VARCHAR
amount FLOAT
transaction_date DATE

Output:

Column Type
quarter VARCHAR
it_spending FLOAT
hr_spending FLOAT
marketing_spending FLOAT
other_spending FLOAT
.
.
.
.
.


Comments

Loading comments