Data Science · Chapter 40 of 43

SQL for Data Science

Most enterprise data lives in SQL databases. A data scientist writes SELECT, JOIN, GROUP BY and window functions daily.

Learn SQL well — it's not going away.

Example 1 (sql)
SELECT city, COUNT(*) AS orders, SUM(amount) AS revenue
FROM orders
WHERE order_date >= '2025-01-01'
GROUP BY city
ORDER BY revenue DESC;

Classic reporting query.

Example 2 (sql)
SELECT user_id, amount,
  RANK() OVER (PARTITION BY user_id ORDER BY amount DESC) AS r
FROM orders;

Window function.

Key points

  • SQL is essential for real projects.
  • JOINs combine tables.
  • GROUP BY aggregates.
  • Window functions unlock ranking / cumulative logic.
💡 Note: Learning to READ someone else's 200-line SQL query is a superpower in a data team.

📝 Quick Quiz

1. SELECT retrieves:

2. Which combines tables?

3. RANK() is a:

4. SQL is used for: