Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Transaction Type Breakdown | CASE WHEN for Aggregates and Reporting
Mastering CASE WHEN in SQL
Avsnitt 4. Kapitel 5
single

single

Challenge: Transaction Type Breakdown

Svep för att visa menyn

Uppgift

Svep för att börja koda

Write a query that, for each month, shows the count of transactions of type 'purchase', 'refund', and 'fee' as separate columns.

  • For each month in the transactions table, count how many transactions have transaction_type equal to 'purchase'.
  • For each month, count how many transactions have transaction_type equal to 'refund'.
  • For each month, count how many transactions have transaction_type equal to 'fee'.
  • Use TO_CHAR(transaction_date, 'YYYY-MM') to extract the month from the date, and name this column month. Show one row per month, with columns purchase_count, refund_count, and fee_count.

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 5
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

some-alt