Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Customer Spending Analysis | CASE WHEN for Aggregates and Reporting
Practice
Projects
Quizzes & Challenges
Frågesporter
Challenges
/
Mastering CASE WHEN in SQL

bookChallenge: Customer Spending Analysis

Uppgift

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.

Lösning

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 2
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

close

bookChallenge: Customer Spending Analysis

Svep för att visa menyn

Uppgift

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.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 2
single

single

some-alt