
PUZZLE 71 CALCULATIONS 297
PUZZLE
71 CALCULATIONS
This problem was posted on a newsgroup in 2006, long after people
should not be writing code this bad. The goal is to select three different
values in the same row based on three conditions, but it does the math
improperly and did not include any DDL. I will start with the original
query text:
SELECT DISTINCT SUM(A.calc_rslt_val + A.calc_adj_val),
SUM(A.unit_rslt_val + A.unit_adj_val),
SUM(OT1.calc_rslt_val + OT1.calc_adj_val),
SUM(OT1.unit_rslt_val + OT1.unit_adj_val),
SUM(OT2.calc_rslt_val + OT2.calc_adj_val),
SUM(OT2.unit_rslt_val + OT2.unit_adj_val)
FROM Table1 AS A, Table1 AS OT1, Table1 AS ...