I have the following query:
select
AD.ALLOCATION_INSTR_ID AS "Allocation Id"
,AD.ALLOCATION_INSTR_VERSION AS "Allocation Version"
,SUM(AC.CHARGE_AMOUNT) AS "Allocation Commission"
,AD.ALLOCATION_ID AS "Sub Allocation Id"
,AD.ALLOCATION_VERSION AS "Sub Allocation Version"
,AC.CHARGE_AMOUNT AS "Allocation Commission"
,B.BLOCK_ID AS "Block Id"
,B.BLOCK_VERSION AS "Block Version"
,B.BLOCK_SOURCE_SYSTEM AS "Block Source System"
,BC.CHARGE_AMOUNT AS "Block Commission"
FROM EQ_MO_ALLOCATION_DETAIL AS AD
LEFT OUTER JOIN EQ_MO_ALLOCATION_DETAIL_CHARGE AS AC
ON AC.ALLOCATION_DETAIL_OID = AD.ALLOCATION_DETAIL_OID
JOIN EQ_MO_ALLOCATION_INSTR AS AI
ON AI.ALLOCATION_INSTR_ID = AD.ALLOCATION_INSTR_ID
AND AI.ALLOCATION_INSTR_VERSION = AD.ALLOCATION_INSTR_VERSION
JOIN EQ_MO_ALLOCATION_INSTR_LINKAGE AS AL
ON AI.ALLOCATION_INSTR_OID = AL.ALLOCATION_INSTR_OID
JOIN EQ_MO_BLOCK AS B
ON B.BLOCK_ID = AL.LINK_PARENT_ID
AND B.BLOCK_VERSION = AL.LINK_PARENT_VERSION
LEFT OUTER JOIN EQ_MO_BLOCK_CHARGE AS BC
ON BC.BLOCK_OID = B.BLOCK_OID
WHERE AD.LAST_UPDATE_TIME BETWEEN '2013-01-17 00:00:00' AND '2013-01-18 00:00:00'
AND AC.CHARGE_NAME = 'Commission'
AND BC.CHARGE_NAME = 'COMMISSION'
AND AD.ALLOCATION_INSTR_VERSION = (SELECT MAX(AD1.ALLOCATION_INSTR_VERSION)
FROM EQ_MO_ALLOCATION_DETAIL AD1
WHERE AD1.ALLOCATION_INSTR_VERSION = AD.ALLOCATION_INSTR_VERSION)
AND B.BLOCK_TIME = (SELECT MAX(b1.BLOCK_TIME)
FROM EQ_MO_BLOCK b1
WHERE b1.BLOCK_ID = B.BLOCK_ID
AND b1.BLOCK_VERSION = B.BLOCK_VERSION)
AND AI.VENDOR_PRODUCT = 'OA'
GROUP BY AD.ALLOCATION_INSTR_ID
ORDER BY 1,2
I'm trying to calculate the total of Allocation Commission via the gathering the total of the Charge amount and display that versus the parent id "Allocation id"
However my group by is some what disjointed:
I join the grouped child commissions to their parent, which is located in another table but I am joining the two via:
LEFT OUTER JOIN EQ_MO_ALLOCATION_DETAIL_CHARGE AS AC
ON AC.ALLOCATION_DETAIL_OID = AD.ALLOCATION_DETAIL_OID
Table AD contains the parent id which can be seen in the first select.
However I'm given the error of:
ERROR: Attribute AD.ALLOCATION_INSTR_VERSION must be GROUPed or used in an aggregate function