3 Essential SQL Queries for Data Analysts: Duplicates, Running Totals, and Gaps

The 3 SQL queries every data analyst should have saved: 1️⃣ Find duplicate records instantly SELECT column, COUNT(*) as cnt FROM table GROUP BY column HAVING COUNT(*) > 1 2️⃣ Running totals (without complex window functions) SELECT date, revenue,  SUM(revenue) OVER (ORDER BY date) as running_total FROM sales 3️⃣ Find gaps in sequential IDs SELECT id+1 as missing_from FROM table t1 WHERE NOT EXISTS (  SELECT 1 FROM table t2  WHERE t2.id = t1.id + 1 ) Save this post. You'll use these weekly. What's your most-used SQL trick? Drop it below 👇 #SQL #DataAnalytics #DataEngineering #JustHiveData #Python

To view or add a comment, sign in

Explore content categories