Write SQL queries to extract, filter, and analyze data for business insights and requirements validation
Enable BAs to validate data requirements, understand current data states, and perform independent data analysis without relying solely on developers.
SELECT column1, column2 -- What do you want?
FROM table_name -- From where?
WHERE condition -- Filter logic
ORDER BY column1 DESC; -- Sorting
WHERE status = 'Active' (Exact match)WHERE quantity > 10 (Comparison)WHERE name LIKE 'Smith%' (Partial match)WHERE status IN ('New', 'Open') (List)WHERE end_date IS NULL (Finding missing data)Summarizing data.
SELECT status, COUNT(*) as total_orders
FROM orders
GROUP BY status;
Connecting related data.
"Are there any duplicate customers by email?"
SELECT email, COUNT(*)
FROM customers
GROUP BY email
HAVING COUNT(*) > 1;
"Are there orders without a valid user?"
SELECT o.order_id
FROM orders o
LEFT JOIN users u ON o.user_id = u.id
WHERE u.id IS NULL;
"How long does it take to ship an order?"
SELECT
AVG(DATEDIFF(day, order_date, shipped_date)) as avg_days_to_ship,
MAX(DATEDIFF(day, order_date, shipped_date)) as max_days
FROM orders
WHERE shipped_date IS NOT NULL;
"What are the distinct values for 'Payment Method' so we can map them?"
SELECT DISTINCT payment_method
FROM transactions;
LIMIT 10 (or TOP 10) when exploring new tables.COUNT(column) ignores NULLs; COUNT(*) counts everything.