Challenge: Unmatched Records Report
Aufgabe
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ösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 1. Kapitel 6
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Suggested prompts:
Can you explain that in more detail?
What are the main benefits or drawbacks?
Can you give me an example?
Großartig!
Completion Rate verbessert auf 4.76
Challenge: Unmatched Records Report
Swipe um das Menü anzuzeigen
Aufgabe
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ösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 1. Kapitel 6
single