Bird
0
0

Consider a table transactions with columns store and sales_amount. What does this query return?

medium📝 query result Q4 of 15
SQL - GROUP BY and HAVING
Consider a table transactions with columns store and sales_amount. What does this query return?

SELECT store, AVG(sales_amount) AS avg_sales FROM transactions GROUP BY store ORDER BY avg_sales DESC;
AAverage sales per store, sorted from highest to lowest average
BTotal sales per store, sorted alphabetically by store
CAll transactions sorted by sales_amount descending
DStores with sales above average, sorted ascending
Step-by-Step Solution
Solution:
  1. Step 1: Analyze SELECT and GROUP BY

    The query groups rows by store and calculates the average sales_amount for each group.
  2. Step 2: Analyze ORDER BY

    The results are ordered by avg_sales in descending order, showing stores with highest average sales first.
  3. Final Answer:

    Average sales per store, sorted from highest to lowest average -> Option A
  4. Quick Check:

    AVG aggregation with descending order [OK]
Quick Trick: GROUP BY aggregates, ORDER BY sorts aggregates [OK]
Common Mistakes:
MISTAKES
  • Confusing AVG with SUM
  • Assuming ORDER BY sorts individual rows
  • Ignoring GROUP BY effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes