TGViewer
Data Engineers Data Engineers @sql_engineer · 11.2K subscribers
Post #976 4.69K
🧠 SQL Interview Question (Running Total of Sales)
📌

sales(order_id, order_date, amount)

❓ Ques :

👉 Calculate the running total of sales for each day

👉 Return order_date, daily_sales, running_total

🧩 How Interviewers Expect You to Think

• Aggregate sales per day 📊
• Use window function for cumulative sum
• Order data correctly for running calculation

💡 SQL Solution

WITH daily_sales AS (
SELECT
order_date,
SUM(amount) AS daily_sales
FROM sales
GROUP BY order_date
)

SELECT
order_date,
daily_sales,
SUM(daily_sales) OVER (
ORDER BY order_date
) AS running_total
FROM daily_sales;

🔥 Why This Question Is Powerful

• Tests window functions (must-know) 🧠
• Very common in real-world reporting
• Frequently asked in analyst & BI roles

❤️ React for more SQL interview questions 🚀
  • ❤ 15
More from @sql_engineer
  1. Aug 29, 2026Example: Source Database → CDC → Only Changed Records → Data Platform CDC is especially us…
  2. Aug 29, 2026🚀 Data Engineering Fundamentals – Part 7 📥 Data Ingestion: How Data Enters a Data Platfo…
  3. Aug 18, 2026🚀 Data Engineering Fundamentals – Part 6 📌 ETL vs ELT: How Data Moves from Source to Des…
  4. Aug 11, 2026📊 The 90-Minutes Business Analytics Masterclass Learn how to transform raw data into powe…
  5. Aug 8, 2026Data Warehouse Stores: Cleaned sales data Customer KPIs Revenue reports Historical busines…
  6. Aug 8, 2026🚀 Data Engineering Fundamentals – Part 4 📌 Databases vs Data Warehouses vs Data Lakes vs…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →