Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Monthly VIP Customer Report | CASE WHEN for Aggregates and Reporting
Mastering CASE WHEN in SQL
Секція 4. Розділ 6
single

single

bookChallenge: Monthly VIP Customer Report

Свайпніть щоб показати меню

Завдання

Проведіть, щоб почати кодувати

Write a SQL query to generate a monthly VIP customer report based on transaction history.

  • Use the transactions table which contains transaction_date, customer_id, and amount columns.
  • Select month (formatted as 'YYYY-MM' using TO_CHAR), customer_id, total_amount, transaction_count, and vip_status.
  • Group by month and customer_id.
  • Calculate total_amount as SUM(amount) and transaction_count as COUNT(*) per customer per month.
  • Use CASE WHEN to set vip_status = 'VIP' if total_amount >= 500 AND transaction_count >= 2, otherwise NULL.
  • Use HAVING to return only rows where both VIP conditions are met.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 6
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt