SQL Mistakes That Give Wrong Numbers
Six made-up orders total 220, but two joins make the same SUM say 505, with no error.
Video #127 ยท SQL and analytics
Steps in the video
Files
- mistakes.py (31 lines)
- run.py (12 lines)
- shop.py (25 lines)
Tested with
Python 3.12.15
What this does not show
Six made-up orders run only in SQLite; PostgreSQL's IS DISTINCT FROM is mentioned from its docs, not run.
Sources
- https://docs.python.org/3.12/library/sqlite3.html
- https://www.postgresql.org/docs/current/functions-comparison.html
- https://www.postgresql.org/docs/current/queries-table-expressions.html
- https://www.sqlite.org/lang_aggfunc.html
- https://www.sqlite.org/lang_corefunc.html
- https://www.sqlite.org/lang_expr.html
Learning IT by Example.