Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Unmatched Records Report | Core Join Types and Their Applications
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
SQL Joins in Depth

bookChallenge: 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 JOIN to join the customers and orders tables on the customer_id field;
  • In your SELECT clause, include:
    • The customer_id from the customers table;
    • The name column from the customers table, but alias it as customer_name;
    • The order_id from the orders table;
    • The order_date from the orders table;
  • Add a column named match_status that uses a CASE statement with the following logic:
    • If order_id is NULL, set the value to 'Customer without orders';
    • If customer_id is NULL, set the value to 'Order without customer';
    • Otherwise, set the value to 'Matched';
  • Order the results so that all unmatched records (where either customer_id or order_id is NULL) appear before the matched records;

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 6
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

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?

close

bookChallenge: 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 JOIN to join the customers and orders tables on the customer_id field;
  • In your SELECT clause, include:
    • The customer_id from the customers table;
    • The name column from the customers table, but alias it as customer_name;
    • The order_id from the orders table;
    • The order_date from the orders table;
  • Add a column named match_status that uses a CASE statement with the following logic:
    • If order_id is NULL, set the value to 'Customer without orders';
    • If customer_id is NULL, set the value to 'Order without customer';
    • Otherwise, set the value to 'Matched';
  • Order the results so that all unmatched records (where either customer_id or order_id is NULL) appear before the matched records;

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 6
single

single

some-alt