Home » SQL & PL/SQL » SQL & PL/SQL » How can I combine 2 queries (GROUP BY) into 1 query
How can I combine 2 queries (GROUP BY) into 1 query [message #756] Fri, 01 March 2002 13:25 Go to next message
Rekha
Messages: 9
Registered: September 2000
Junior Member
Hi,

I have 2 queries
1.
SELECT account_id,SUM(transaction_amount) total_cleared_funds
FROM customer_cash_adjustments
WHERE CLEAR_DATE <= SYSDATE
GROUP BY account_id;
2.
SELECT account_id,SUM(transaction_amount) total_uncleared_funds
FROM customer_cash_adjustments
WHERE CLEAR_DATE > SYSDATE
GROUP BY account_id;

Ultimately all I want is a single result set containing the
account_id total_cleared_funds total_uncleared funds

Eg:

account_id total_cleared_funds total_uncleared funds
---------- ------------------ ---------------------
100 56.0 345.0
200 0 4567
300 1234
400 2345

How can I get this?

Thanks,
Rekha
Re: How can I combine 2 queries (GROUP BY) into 1 query [message #774 is a reply to message #756] Mon, 04 March 2002 01:41 Go to previous message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
try this
SELECT account_id,SUM(transaction_amount),null total_cleared_funds
FROM customer_cash_adjustments
WHERE CLEAR_DATE <= SYSDATE
GROUP BY account_id
UNION
SELECT account_id,null,SUM(transaction_amount) total_uncleared_funds
FROM customer_cash_adjustments
WHERE CLEAR_DATE > SYSDATE
GROUP BY account_id;
Previous Topic: Dates in the same calendar week.
Next Topic: sql
Goto Forum:
  


Current Time: Thu Apr 18 09:37:45 CDT 2024