Subject | Getting the average of a grouped summation |
---|---|
Author | Paul R. Gardner |
Post date | 2010-09-15T14:54:32Z |
I have the following data:
JOB AMOUNT
1 1.00
1 1.00
2 4.00
Of course there's a primary key field and other data along with these.
The point is that I have $2 for job 1 and $4 for job 2. Job 1's records
are split though.
SELECT AVG(AMOUNT) FROM TABLE
In this case would return 2. This is not what I want.
SELECT SUM(AMOUNT) FROM TABLE GROUP BY JOB
This query returns the correct job totals: 2 and 4.
SELECT AVG((SELECT SUM(AMOUNT) FROM TABLE GROUP BY JOB))
FROM RDB$DATABASE
This query to me should average the 2 and the 4 and return 3 which is
the result I'm looking for. Instead it gives a multiple rows in
singleton select.
Any ideas? I need this to run on FB 1.5 so I cannot use a derived
table.
JOB AMOUNT
1 1.00
1 1.00
2 4.00
Of course there's a primary key field and other data along with these.
The point is that I have $2 for job 1 and $4 for job 2. Job 1's records
are split though.
SELECT AVG(AMOUNT) FROM TABLE
In this case would return 2. This is not what I want.
SELECT SUM(AMOUNT) FROM TABLE GROUP BY JOB
This query returns the correct job totals: 2 and 4.
SELECT AVG((SELECT SUM(AMOUNT) FROM TABLE GROUP BY JOB))
FROM RDB$DATABASE
This query to me should average the 2 and the 4 and return 3 which is
the result I'm looking for. Instead it gives a multiple rows in
singleton select.
Any ideas? I need this to run on FB 1.5 so I cannot use a derived
table.