Challenge: Unmatched Records Report
Tarefa
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;
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 6
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Incrível!
Completion taxa melhorada para 4.76
Challenge: Unmatched Records Report
Deslize para mostrar o menu
Tarefa
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;
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 6
single