SQL & Python for Data Analysts: Explaining Queries and Clarifying Data Requests
Quizlet Set: Explaining Queries
Explaining Queries (WITH SQL / PYTHON)
Model Examples (10)
1. SELECT * FROM customers WHERE country = 'Germany';
This query retrieves all customers from Germany.
2. SELECT * FROM orders WHERE order_date >= '2025-01-01';
This query filters orders placed since 1st January 2025.
3. SELECT product_id, COUNT(*) FROM orders GROUP BY product_id;
This query counts how many orders each product has.4. SELECT department, AVG(salary) FROM employees GROUP BY department;
This query calculates the average salary by department.5. SELECT * FROM products ORDER BY price DESC;
This query sorts products by price in descending order.6. SELECT c.name, o.order_id
FROM customers c
JOIN orders o ON c.id = o.customer_id;
This query joins customers with their orders.7. SELECT customer_id, SUM(amount)
FROM payments
GROUP BY customer_id;
This query calculates total payments per customer.8. SELECT * FROM users WHERE last_login < '2025-01-01';
This query identifies users who have not logged in recently.9. SELECT product_id, SUM(quantity) AS total_sold
FROM sales
GROUP BY product_id
ORDER BY total_sold DESC
LIMIT 10;
This query returns the top 10 best-selling products.10. SELECT region, SUM(revenue)
FROM sales
GROUP BY region;
This query compares total revenue across regions.Extra Practice (10 examples)
1. SELECT * FROM orders WHERE amount > 1000;
This query retrieves all high-value orders above 1000.2. SELECT COUNT(*) FROM users WHERE status = 'inactive';
This query counts inactive users.3. SELECT DATE(order_date), SUM(amount)
FROM orders
GROUP BY DATE(order_date);
This query aggregates daily sales.4. SELECT * FROM employees WHERE hire_date >= '2025-01-01';
This query returns employees hired this year.5. SELECT customer_id, COUNT(order_id)
FROM orders
GROUP BY customer_id;
This query counts how many orders each customer placed.6. SELECT category, AVG(rating)
FROM reviews
GROUP BY category;
This query calculates average ratings per category.7. SELECT * FROM products WHERE stock < 10;
This query identifies products with low inventory.8. SELECT region, SUM(sales)
FROM sales
GROUP BY region
HAVING SUM(sales) > 10000;
This query filters regions with high total sales.9. SELECT DISTINCT customer_id FROM orders;
This query finds unique customers who placed orders.10. SELECT * FROM logs WHERE error = TRUE;
This query retrieves system error logs.Python examples
1. df[df["country"] == "Germany"]
This code filters data to get all rows where country is Germany.2. df.groupby("department")["salary"].mean()
This code calculates average salary by department.3. df.sort_values("price", ascending=False)
This code sorts products by price in descending order.Explaining Queries Practice (SQL + Python → Explanation)
Essential Clarifying Questions
What questions do you think can help you understand the request better?
How to make sure you provide what the stakeholders expect?
Real-Life Dialogues (Data Analyst & Manager)
Dialogue 1: Customer Report
Manager: I need a report on our customers.
Data Analyst: Could you clarify the requirements?
Manager: I want to understand customer activity.
Data Analyst: What time period should we analyze?
Manager: The last six months.
Data Analyst: Which metrics are important?
Manager: Purchases and total spending.
Data Analyst: Great. I’ll write a query to retrieve data and generate a report.
Dialogue 2: Sales Drop
Manager: Sales dropped last quarter. Can you check?
Data Analyst: What is the main business objective?
Manager: Find the reason for the drop.
Data Analyst: Should I compare results with the previous quarter?
Manager: Yes.
Data Analyst: I’ll filter data by region and time period and analyze trends.
Dialogue 3: Marketing Dashboard
Manager: We need a dashboard for marketing.
Data Analyst: Who is the target audience?
Manager: Marketing managers.
Data Analyst: What KPIs should be included?
Manager: Traffic, conversions, campaign performance.
Data Analyst: How often will it be updated?
Manager: Daily.
Data Analyst: I’ll check data availability and build a dashboard.
Dialogue 4: Missing Information
Manager: I need retention statistics.
Data Analyst: Which customer segment?
Manager: New customers.
Data Analyst: What time period should we use?
Manager: Last year.
Data Analyst: What output format do you need?
Manager: Dashboard.
Data Analyst: Perfect, I’ll proceed.
Dialogue 5: Product Analysis
Manager: Find our most profitable products.
Data Analyst: What data source should I use?
Manager: Sales database.
Data Analyst: Report or visualization?
Manager: Visualization.
Data Analyst: I’ll write a SQL query to retrieve data and use Python to analyze trends.
Final Speaking/Writing Activity
Task: Analyst Simulation
Give students these requests:
- I need customer insights.
- I need a sales report.
- Analyze user behavior.
- Build a dashboard for management.
- Explain why revenue decreased.
Instructions:
Students must:
- ask at least 5 clarifying questions
- use at least 3 target phrases
- agree on next steps
Target phrases:
- clarify requirements
- time period
- metrics
- expected output
- data source
- business objective