TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst · 76.7K subscribers
Post #2719 1.68K
SELECT COUNT(*) AS total_employees
FROM employees;


Answer 2

SELECT AVG(salary) AS average_salary
FROM employees;


Answer 3

SELECT MAX(price) AS highest_price
FROM products;


Answer 4

SELECT MIN(price) AS lowest_price
FROM products;


Answer 5

SELECT
SUM(amount) AS total_revenue
FROM orders
WHERE order_status = 'Completed';


Answer 6

SELECT
COUNT(DISTINCT customer_id) AS unique_customers
FROM orders;


Answer 7

SELECT
MAX(amount) AS largest_order
FROM orders;


Answer 8

SELECT
AVG(amount) AS average_order_value
FROM orders
WHERE order_status = 'Completed';


Answer 9

SELECT
COUNT(*) AS completed_orders
FROM orders
WHERE order_status = 'Completed';


Answer 10

SELECT
SUM(amount) AS total_revenue,
COUNT(DISTINCT customer_id) AS unique_customers
FROM orders
WHERE order_status = 'Completed';


🔥 Mini Challenge

You have an orders table: order_id | customer_id | amount | status

Business requirement: Calculate: Total completed orders, Unique completed customers, Total completed revenue, Average completed order value, Largest completed order

Solution

SELECT
COUNT(*) AS completed_orders,
COUNT(DISTINCT customer_id) AS unique_customers,
SUM(amount) AS total_revenue,
AVG(amount) AS average_order_value,
MAX(amount) AS largest_order
FROM orders
WHERE status = 'Completed';


Expected result: completed_orders = 4, unique_customers = 3, total_revenue = 15500, average_order_value = 3875, largest_order = 6000

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