Verification Log: 37-current-run.txt

Original companion example or verification log for the tutorial, preserved with user paths redacted; execution scope follows the recorded run.

SQLite 3.53.1
Constraint blocked negative amount: CHECK constraint failed: amount > 0

① Paid revenue per plan (JOIN + GROUP BY + HAVING)
  plan | n_orders | revenue
  team | 2 | 1498.0
  pro | 3 | 790.0

② LEFT JOIN: including users with zero orders
  name | n_orders | total
  Wu Bi | 2 | 1498.0
  Lin Xiaoxing | 2 | 425.0
  Wang Yun | 2 | 377.0
  Zhou He | 1 | 30.0
  Zheng Ji | 0 | 0

③ CTE + window functions: most recent order per user and cumulative daily revenue
  user_id | order_id | created_at
  U1 | O2 | 2026-10-03
  U2 | O3 | 2026-10-02
  U3 | O5 | 2026-10-05
  U5 | O7 | 2026-10-07
  created_at | day_rev | cum_rev
  2026-10-01 | 365.0 | 365.0
  2026-10-02 | 1299.0 | 1664.0
  2026-10-03 | 60.0 | 1724.0
  2026-10-05 | 199.0 | 1923.0
  2026-10-06 | 365.0 | 2288.0

④ Pitfall 1: NOT IN with NULL — finding users who have never referred anyone
  name
  name
  Zhou He
  Zheng Ji
  Wang Yun
  NOT IN returned 0 rows (subquery contains NULL, condition evaluates to UNKNOWN); NOT EXISTS returned 3 rows

⑤ Pitfall 2: COUNT(*) vs COUNT(column)
  all_rows | non_null_referrer
  5 | 3

⑥ Pitfall 3: SQL injection
  String concatenation: returned order count 7 (attacker saw all orders)
  Parameterized query: returned order count 0
Back to Tutorials Back to Learn →Back to top ↑
On this page
Tutorial diagram100%
Tutorial diagram