Skip to content
RED SAGSkills

Orders by Day of Week

Break orders down by day of the week. Use SQLite's strftime('%w', date), where 0 is Sunday and 6 is Saturday, as an integer weekday_num. Map it to a weekday_name of Sun, Mon, Tue, Wed, Thu, Fri or Sat. Only weekdays that have orders appear.

- order_count: number of orders - revenue: sum of amount, ROUND(x, 2)

Return columns weekday_num, weekday_name, order_count, revenue. Order by weekday_num ascending.

Schema

CREATE TABLE orders (
  order_id INTEGER PRIMARY KEY,
  order_date TEXT NOT NULL,
  amount REAL NOT NULL
);

Sample data

orders

order_idorder_dateamount
12026-03-01120
22026-03-0280
32026-03-0645.5
42026-03-0860
52026-03-13210.25
62026-03-1433
72026-03-0919.99
Hint 1

strftime('%w', d) returns text such as '0'; CAST it to INTEGER so the ordering is numeric.

Hint 2

A simple CASE expr WHEN value THEN ... maps the numbers to names.

Good practice for: Data Analyst, Digital Marketing Specialist, Business Analyst, Product Manager

SQL (SQLite)

Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.