Need help with joining two grouped sub queries to my grouped main query

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I was wondering if it was having an issue because I'm using an aggregate function and doing a GROUP BY and then trying to pull it into another query that I was also doing a GROUP BY and aggregate on also.

I felt that your queries might be not consistent with each other and with the result what you are looking for.

For example:
(1) First query had ADRSN IN ('BT', 'B4', 'B5'). Second and third queries had ADRSN = 'B5'.
Did that mean you don't want to add ADADJA into SUM(ADADJA) for ADRSN IN ('BT', 'B4')?

(2) First query had ADCUST NOT IN ('076832211'). But, second and third queries had not predicate for ADCUST.
Is the value of ( BCCDCD.CDCD_FIRST || ' ' ) || BCCDCD.CDCD_LAST unneccesary for ADCUST = '076832211'?

(3) Column names Acct_Num and Cust_Name in what you are looking for are not appear in your queries.
(I could suppose ADCUST and TCHR_NAME might be corresponded to them. But, not sure!)

(4) Second and third queries had ADRSN in GROUP BY item. But, it was not in what you are looking for.

Anyway,
this example might be worth to try...
(though you may want to modify some predicates.)

Code:

SELECT f.ADCUST AS Acct_Num
, (SELECT CDCD_FIRST || ' ' || CDCD_LAST
FROM CDATA.BCCDCD
WHERE CDCD_CUSTOMER_NUMBER = f.ADCUST
) AS Cust_Name
, SUM( CASE
WHEN f.ADRSN = 'B5'
AND f.ADADJA > 0 THEN
f.ADADJA
END ) AS B5DTL
, SUM( CASE
WHEN f.ADRSN = 'B5'
AND f.ADADJA < 0 THEN
f.ADADJA
END ) AS B5CTL
FROM ARD.FBF800 AS f
WHERE f.ADCUST NOT IN ('076832211')
AND f.ADRSN IN ('BT', 'B4', 'B5')
AND f.ADTRD BETWEEN 20120801 AND 20130731
GROUP BY
f.ADCUST

Thanks for the feedback Tonkuma. My apologies for any confusion. I think that I need to provide what each query is grabbing and how it is being grouped/aggregated so that you can see how I would get that end result that is also grouped/aggrgated again. I started working up an Excel sheet yesterday with more detail and some sample data but might take me a few days to get it all together and posted while I complete other tasks. Hope that once I provide that it will be easier to work out a solution. I really appreciate your responses.