Order Summary Stats
Easysql
Write a query returning three aggregate columns over the whole orders table: order_count (total number of orders), total_revenue (sum of all amount), and avg_amount (integer average, using SUM(amount) DIV COUNT(*)).
sqlCREATE TABLE orders ( id INTEGER PRIMARY KEY, customer_name TEXT NOT NULL, amount INTEGER NOT NULL, order_date DATE NOT NULL );
Sample data:
sqlINSERT INTO orders (id, customer_name, amount, order_date) VALUES (1, 'Asha', 500, '2026-03-05'), (2, 'Rohan', 300, '2026-03-20'), (3, 'Neha', 700, '2026-04-02'), (4, 'Asha', 200, '2026-03-28');
Example 1
Input
(none)
Output
order_count total_revenue avg_amount 4 1700 425
COUNT(), SUM(amount), and integer division combine into one summary row. Reference: `SELECT COUNT() AS ordercount, SUM(amount) AS totalrevenue, SUM(amount) DIV COUNT(*) AS avg_amount FROM orders;`