2/34
Part 1 of 6 · WindowsLearn

The lesson's table: seven orders from four users

Every query in this lesson runs on one small table, built so each trap shows.

order_iduser_idordered_onamount
112026-03-0130
222026-03-0120
312026-03-0345
432026-03-0325
522026-03-0935
612026-03-0245
742026-03-1050

It's small on purpose. Here are the same orders laid out by the day they happened:

Each order as #id, user, amount: #1 u1 30 is order 1, user 1, 30.

Mar 01Mar 02Mar 03Mar 04 to 08Mar 09Mar 10
#1 u1 30#6 u1 45#3 u1 45no orders#5 u2 35#7 u4 50
#2 u2 20#4 u3 25

Each odd detail breaks a query later in the lesson:

  • Order 6 was entered after orders 1 to 5, but it happened on March 2, between user 1's other two orders.
  • User 1 has two orders of 45.
  • March 1 and March 3 each have two orders.
  • Nothing happens from March 4 to March 8.

To follow along, load it into SQLite from Python. The practice tests run your queries the same way:

import sqlite3

con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE orders (order_id INTEGER, user_id INTEGER, "
            "ordered_on TEXT, amount INTEGER)")
con.executemany("INSERT INTO orders VALUES (?, ?, ?, ?)", [
    (1, 1, "2026-03-01", 30), (2, 2, "2026-03-01", 20),
    (3, 1, "2026-03-03", 45), (4, 3, "2026-03-03", 25),
    (5, 2, "2026-03-09", 35), (6, 1, "2026-03-02", 45),
    (7, 4, "2026-03-10", 50),
])
print(sqlite3.sqlite_version)
print(con.execute("""
    SELECT user_id, COUNT(*) FROM orders
    GROUP BY user_id ORDER BY user_id
""").fetchall())
3.53.4
[(1, 3), (2, 2), (3, 1), (4, 1)]

The first line is the SQLite version. Every query and every result in this lesson comes from this engine. Where engines differ, on frames, ties or dates, the lesson says which one it means.

The tests compare a list of tuples like the second line with the expected list. So the column order and the final ORDER BY are part of your answer.