easy

Orders with Customer Names

You are working as a Data Engineer for an online retail company. The business team wants a report that combines order details with customer information so they can better understand who is placing each order.

Currently, the data is stored across two separate tables: one for customers and one for orders. To generate the required report, you will need to join these tables using a common key.

Schema Summary:

customers table:
- customer_id (INT)
- customer_name (TEXT)
- city (TEXT)

orders table:
- order_id (INT)
- customer_id (INT)
- order_date (DATE)
- amount (NUMERIC)

Requirements:

  • Join the customers and orders tables.

  • Return the following columns: order_id, customer_name, order_date, amount.

  • Only include orders where the amount is greater than 100.

  • Sort the result by order_date in ascending order.

Hints:

Use an INNER JOIN to combine both tables based on customer_id. A common mistake is joining on the wrong column or forgetting to filter after the join.

Make sure to apply the WHERE condition after the join to filter high-value orders correctly.

1
2
3
4
5
Preparing...
Orders with Customer Names

You are working as a Data Engineer for an online retail company. The business team wants a report that combines order details with customer information so they can better understand who is placing each order. Currently, the data is stored across two separate tables: one for customers and one for orders. To generate the required report, you will need to join these tables using a common key. Schema Summary: customers table: - customer_id (INT) - customer_name (TEXT) - city (TEXT) orders table: - order_id (INT) - customer_id (INT) - order_date (DATE) - amount (NUMERIC) Requirements: Join the customers and orders tables. Return the following columns: order_id, customer_name, order_date, amount. Only include orders where the amount is greater than 100. Sort the result by order_date in ascending order. Hints: Use an INNER JOIN to combine both tables based on customer_id. A common mistake is joining on the wrong column or forgetting to filter after the join. Make sure to apply the WHERE condition after the join to filter high-value orders correctly.

Table Setup (SQL Schema)

CREATE TABLE customers (customer_id INT, customer_name TEXT, city TEXT);

CREATE TABLE orders (order_id INT, customer_id INT, order_date DATE, amount NUMERIC);

INSERT INTO customers (customer_id, customer_name, city) VALUES
(1, 'Alice', 'New York'),
(2, 'Bob', 'Los Angeles'),
(3, 'Charlie', 'Chicago');

INSERT INTO orders (order_id, customer_id, order_date, amount) VALUES
(101, 1, '2023-01-01', 50),
(102, 1, '2023-01-02', 150),
(103, 2, '2023-01-01', 200),
(104, 3, '2023-01-03', 80),
(105, 2, '2023-01-04', 120);
Home Videos Quiz Blog