TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst · 76.7K subscribers
Post #2580 2.23K
SQL Project Series #3

E-Commerce Sales Analysis – Intermediate SQL Business Questions

Let's solve more real-world business problems using SQL.

Business Questions

11. Find Repeat Customers

SELECT

customer_id,

COUNT(order_id) AS total_orders

FROM orders

GROUP BY customer_id

HAVING COUNT(order_id) > 1;

12. Find Customers Who Never Placed an Order

SELECT

c.customer_id,

c.customer_name

FROM customers c

LEFT JOIN orders o

ON c.customer_id = o.customer_id

WHERE o.order_id IS NULL;

13. Find Inactive Customers (No Orders in the Last 90 Days)

SELECT

c.customer_id,

c.customer_name

FROM customers c

LEFT JOIN orders o

ON c.customer_id = o.customer_id

GROUP BY c.customer_id, c.customer_name

HAVING MAX(o.order_date) < CURRENT_DATE - INTERVAL '90 days'

OR MAX(o.order_date) IS NULL;

14. Find the Best-Selling Product Category

SELECT

p.category,

SUM(oi.quantity) AS units_sold

FROM products p

JOIN order_items oi

ON p.product_id = oi.product_id

GROUP BY p.category

ORDER BY units_sold DESC

LIMIT 1;

15. Find the Highest Revenue Product

SELECT

p.product_name,

SUM(oi.quantity * oi.unit_price) AS revenue

FROM products p

JOIN order_items oi

ON p.product_id = oi.product_id

GROUP BY p.product_name

ORDER BY revenue DESC

LIMIT 1;

16. Find the Lowest Revenue Product

SELECT

p.product_name,

SUM(oi.quantity * oi.unit_price) AS revenue

FROM products p

JOIN order_items oi

ON p.product_id = oi.product_id

GROUP BY p.product_name

ORDER BY revenue

LIMIT 1;

17. Calculate Average Products per Order

SELECT

ROUND(AVG(product_count), 2) AS avg_products_per_order

FROM (

SELECT

order_id,

SUM(quantity) AS product_count

FROM order_items

GROUP BY order_id

) t;

18. Find Orders Worth More Than 10,000

SELECT

order_id,

SUM(quantity * unit_price) AS order_value

FROM order_items

GROUP BY order_id

HAVING SUM(quantity * unit_price) > 10000;

19. Find Customers with the Highest Average Order Value

SELECT

customer_id,

ROUND(AVG(order_value), 2) AS avg_order_value

FROM (

SELECT

o.customer_id,

o.order_id,

SUM(oi.quantity * oi.unit_price) AS order_value

FROM orders o

JOIN order_items oi

ON o.order_id = oi.order_id

GROUP BY o.customer_id, o.order_id

) t

GROUP BY customer_id

ORDER BY avg_order_value DESC;

20. Find the Top 3 Cities by Revenue

SELECT

c.city,

SUM(oi.quantity * oi.unit_price) AS revenue

FROM customers c

JOIN orders o

ON c.customer_id = o.customer_id

JOIN order_items oi

ON o.order_id = oi.order_id

GROUP BY c.city

ORDER BY revenue DESC

LIMIT 3;

SQL Concepts Practiced

• LEFT JOIN

• HAVING

• Aggregate Functions

• Nested Queries

• GROUP BY

• Business KPI Analysis

• Customer Segmentation

• Revenue Analysis

💡 Double Tap ❤️ For More
  • ❤ 8
More from @sqlanalyst
  1. Oct 8, 2026🎓 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝘄𝗶𝘁𝗵 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗲𝘀! 🚀🔥 Upgr…
  2. Oct 7, 2026🚀𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 | 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰…
  3. Oct 7, 2026SQL Interview Series — Part 4 📌 Question 4: Find the Highest Salary in Each Department Su…
  4. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
  5. Sep 29, 2026SQL Interview Series — Part 2 📌 Question 2: Find Duplicate Records Suppose you have an Em…
  6. Sep 29, 2026𝗙𝗥𝗘𝗘 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗧𝗼 𝗟𝗲𝗮𝗿𝗻 𝗔𝗜 𝗶𝗻 𝟮𝟬𝟮𝟲🚀 ​ Explore 6 free resource…
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 →