A dashboard repeatedly asks for the total sales and order count per region from the 2,000-row sales table. Re-aggregating on every page view is wasteful when the numbers change only once a day.
Many databases offer materialized views for this. SQLite does not, but you can emulate one with a regular table filled from a query. Create a table named sales_by_region with the columns region, total_amount (sum of amount) and order_count (number of sales), then select all of its rows ordered by region.
sales_by_region with CREATE TABLE ... AS SELECTregion, total_amount, order_countSELECT * FROM sales_by_region ORDER BY region;CREATE TABLE name AS SELECT ... stores the query result as a real table.
Use GROUP BY region with SUM(amount) and COUNT(*) and alias them.
No results yet
Run your code to check it against the examples, or submit to run every test.