Challenge: Unmatched Records Report
Uppgift
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;
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 6
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Fantastiskt!
Completion betyg förbättrat till 4.76
Challenge: Unmatched Records Report
Svep för att visa menyn
Uppgift
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;
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 6
single