Challenge: Unmatched Records Report
Tarea
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;
Solución
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 1. Capítulo 6
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Suggested prompts:
Can you explain that in more detail?
What are the main benefits or drawbacks?
Can you give me an example?
Genial!
Completion tasa mejorada a 4.76
Challenge: Unmatched Records Report
Desliza para mostrar el menú
Tarea
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;
Solución
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 1. Capítulo 6
single