As can be seen, this schema is slightly
denormalisedas the number of lines per transaction areprecalculated in the
column. This will turn out to be quite useful for this calculation, but it isn’t strictly necessary.
Now, in the previously linked Stack Overflow question, a report was desired that would calculate:
– An aggregation of sums as provided by the line items
– An aggregation of averages as provided by the transactions
As Lukas points out, doing this in two queries is easy, but doing it in one is sublime.