0% found this document useful (0 votes)
19 views3 pages

Please Help Me With Real Time SQL Query For ETL T...

The document outlines SQL queries for data validation, transformation, quality checks, joins, and aggregations. It includes scenarios such as identifying invalid order statuses, calculating total order amounts by country, and finding duplicate customer IDs. Additionally, it provides interview tips for articulating thought processes, writing clean code, testing queries, and demonstrating SQL knowledge.

Uploaded by

postbox181
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Please Help Me With Real Time SQL Query For ETL T...

The document outlines SQL queries for data validation, transformation, quality checks, joins, and aggregations. It includes scenarios such as identifying invalid order statuses, calculating total order amounts by country, and finding duplicate customer IDs. Additionally, it provides interview tips for articulating thought processes, writing clean code, testing queries, and demonstrating SQL knowledge.

Uploaded by

postbox181
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Data Validation & Transformation


● Scenario: You have an order table with columns: order_id, customer_id, order_date,
total_amount, status.
Requirement: Identify orders with invalid status (e.g., only 'Pending', 'Shipped', 'Delivered' are
valid statuses).

SELECT
order_id, customer_id, order_date, total_amount, status
FROM
orders
WHERE
status NOT IN ('Pending', 'Shipped', 'Delivered');

● Scenario: You have a customer table with customer_id and country and an orders table.
Requirement: Calculate the total order amount for each country.

SELECT
c.country, SUM(o.total_amount) AS total_order_amount
FROM
customers c
JOIN
orders o ON c.customer_id = o.customer_id
GROUP BY
c.country;

● Scenario: You have a table with date and sales columns.


Requirement: Calculate the daily sales difference compared to the previous day.

SELECT
date,
sales - LAG(sales) OVER (ORDER BY date) AS daily_sales_difference
FROM
sales_table;

2. Data Quality Checks


● Scenario: You have a table with customer_id (unique identifier).
Requirement: Query to find duplicate customer_id values.

SELECT
customer_id, COUNT(*)
FROM
customers
GROUP BY
customer_id
HAVING
COUNT(*) > 1;
● Scenario: You have a table with an email column.
Requirement:Qquery to identify invalid email addresses (e.g., missing '@' symbol).

SELECT
email
FROM
customers
WHERE
email NOT LIKE '%@%';

● Scenario: You have a table with date_of_birth column.


Requirement:Query to identify records where date_of_birth is in the future.

SELECT
*
FROM
customers
WHERE
date_of_birth > CURRENT_DATE;

3. Data Joins & Aggregations


● Scenario: You have two tables: orders and order_items.
Requirement: Query to find the total number of orders for each product.

SELECT
oi.product_id, COUNT(DISTINCT o.order_id) AS total_orders
FROM
orders o
JOIN
order_items oi ON o.order_id = oi.order_id
GROUP BY
oi.product_id;

● Scenario: You have a table with customer_id and order_date.


Requirement: Query to find the date of the first order for each customer.

SELECT
customer_id, MIN(order_date) AS first_order_date
FROM
orders
GROUP BY
customer_id;

4. Window Functions
● Scenario: You have a table with order_id, customer_id, and order_date.
Requirement: Query to find the most recent order date for each customer.

SELECT
customer_id, order_date
FROM
(
SELECT
customer_id, order_date,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY
order_date DESC) AS rn
FROM
orders
) ranked_orders
WHERE
rn = 1;

Tips for the Interview


● Explain your thought process: Clearly articulate your approach to solving the problem.
● Write clean and readable code: Use proper indentation and meaningful aliases.
● Test your queries: Run the queries with sample data to verify the results.
● Ask clarifying questions: Don't hesitate to ask questions if you're unsure about the
requirements or the data.
● Demonstrate your understanding of SQL concepts: Explain the purpose of different
clauses (e.g., WHERE, GROUP BY, HAVING, ORDER BY) and window functions.

Remember to adapt these examples to the specific requirements and data structures
presented in the interview.

I hope this helps! Let me know if you have any other questions.

You might also like