Challenge: Unmatched Records Report
Завдання
Swipe to start coding
Write a SQL query to produce a report of all customers and all orders, showing unmatched records and matched pairs using a FULL OUTER JOIN.
Follow these steps:
- Use a
FULL OUTER JOINto join thecustomersandorderstables on thecustomer_idfield; - In your
SELECTclause, include:- The
customer_idfrom thecustomerstable; - The
namecolumn from thecustomerstable, but alias it ascustomer_name; - The
order_idfrom theorderstable; - The
order_datefrom theorderstable;
- The
- Add a column named
match_statusthat uses aCASEstatement with the following logic:- If
order_idis NULL, set the value to'Customer without orders'; - If
customer_idis NULL, set the value to'Order without customer'; - Otherwise, set the value to
'Matched';
- If
- Order the results so that all unmatched records (where either
customer_idororder_idis NULL) appear before the matched records;
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 6
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Чудово!
Completion показник покращився до 4.76
Challenge: Unmatched Records Report
Свайпніть щоб показати меню
Завдання
Swipe to start coding
Write a SQL query to produce a report of all customers and all orders, showing unmatched records and matched pairs using a FULL OUTER JOIN.
Follow these steps:
- Use a
FULL OUTER JOINto join thecustomersandorderstables on thecustomer_idfield; - In your
SELECTclause, include:- The
customer_idfrom thecustomerstable; - The
namecolumn from thecustomerstable, but alias it ascustomer_name; - The
order_idfrom theorderstable; - The
order_datefrom theorderstable;
- The
- Add a column named
match_statusthat uses aCASEstatement with the following logic:- If
order_idis NULL, set the value to'Customer without orders'; - If
customer_idis NULL, set the value to'Order without customer'; - Otherwise, set the value to
'Matched';
- If
- Order the results so that all unmatched records (where either
customer_idororder_idis NULL) appear before the matched records;
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 6
single