I have a query with several aggregate functions and then a few grouped columns. I want to take one of the grouped columns out of the group and perform some sort of aggregate "concatenating" of all the VARCHAR values it has. (Ideally in a new carriage separated list).
Here is my query and I note where I d like to do this:
SELECT rownum, F.*
FROM (SELECT
c.logical_type "MerchantType",
c.merchant_id "MerchantID",
c.m_name "MerchantName",
m.m_name "TransferredBy", /* <----- Make this aggregate */
SUM(DECODE(b.ba_price,null,0,DECODE(b.BILL_SRVC_ID, CREDITCHANGE ,0,b.ba_price))) "TotalValue",
sum(DECODE(b.ba_price,null,0,DECODE(b.BILL_SRVC_ID, CREDITCHANGE ,b.ba_price,0))) "LimitChange",
SUM(DECODE(b.ba_status, bdone ,1,0)) "TxnCount",
sum(to_number(decode(substr(b.ba_merchant_freetext,1,10), Commission ,substr(b.ba_merchant_freetext, 12,(instr(b.ba_merchant_freetext, ; ,1,1)-12))))) "Commission"
FROM bill_auth0 b,
merchant0 m,
merchant0 c
WHERE
b.srvc_prod_id = TRANSFER
AND b.ba_channel = WPSS
AND b.ba_status IN ( bdone )
AND b.merchant_id = m.merchant_id
AND b.customer_id = c.merchant_id
AND b.ba_timestamp BETWEEN to_date( 11/01/2009 , MM/DD/YYYY )
AND to_date( 11/17/2009 , MM/DD/YYYY )+1
GROUP BY
c.logical_type,
c.merchant_id,
c.m_name,
m.m_name /* <-- Remove from Grouped By */
ORDER BY c.logical_type, c.merchant_id, m.m_name) F;
So essentially I want to be able to have a result where "TransferredBy" would look something like:
Merchant1
Merchant2
Merchant3
if there were 3 seperate m.m_name matches to this Group Row.