Challenge: Monthly VIP Customer Report
You may encounter the TO_CHAR function in this task. TO_CHAR is used to convert dates or numbers into formatted strings, which lets you customize how values are displayed. For example, you can format a date as 'YYYY-MM' to show only the year and month.
Дякуємо за ваш відгук!
single
Challenge: Monthly VIP Customer Report
Свайпніть щоб показати меню
You may encounter the TO_CHAR function in this task. TO_CHAR is used to convert dates or numbers into formatted strings, which lets you customize how values are displayed. For example, you can format a date as 'YYYY-MM' to show only the year and month.
Проведіть, щоб почати кодувати
Write a SQL query to generate a monthly VIP customer report based on transaction history.
- Use the
transactionstable which containstransaction_date,customer_id, andamountcolumns. - Select
month(formatted as'YYYY-MM'usingTO_CHAR),customer_id,total_amount,transaction_count, andvip_status. - Group by
monthandcustomer_id. - Calculate
total_amountasSUM(amount)andtransaction_countasCOUNT(*)per customer per month. - Use
CASE WHENto setvip_status = 'VIP'iftotal_amount >= 500ANDtransaction_count >= 2, otherwiseNULL. - Use
HAVINGto return only rows where both VIP conditions are met.
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат