Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Customer Spending Analysis | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Mastering CASE WHEN in SQL
Sectionย 1. Chapterย 20
single

single

bookChallenge: Customer Spending Analysis

Swipe to show menu

Task

Swipe to start coding

Write a query that shows, for each customer, the total 'purchase' and 'refund' amounts as separate columns.

  • Select customer_id from the transactions table.
  • Calculate the sum of amount for transactions where transaction_type is 'purchase' and display it as total_purchase.
  • Calculate the sum of amount for transactions where transaction_type is 'refund' and display it as total_refund.
  • Group the results by customer_id.
  • Display one row per customer.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Sectionย 1. Chapterย 20
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt