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.

 
Go Back  dBforums > Database Server Software > DB2 > Basic SQL question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-17-04, 13:08
markjason markjason is offline
Registered User
 
Join Date: Jun 2004
Posts: 46
Basic SQL question

Hi All !

I have a Basic Question,
Can i do following Statements in a single SQL statment

1) select count(*) as recordcount,sum(amt) as total amount from table
2) select count(*) as recordcount,sum(amt) as total amount from table_exception
3) I need to add both the values respectively from statment 1 and 2 and get the result .

Hope I am clear

Thanks
Mark.
Reply With Quote
  #2 (permalink)  
Old 11-17-04, 13:29
markjason markjason is offline
Registered User
 
Join Date: Jun 2004
Posts: 46
I got it worked...like this

select count(*)+(select count(*) from table),sum(tot_invc_amt)+(select sum(amt) from table_exception) from table

Thanks
Mark.
Reply With Quote
  #3 (permalink)  
Old 11-17-04, 13:45
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
select sum(recordcount), sum(total)
from
(select count(*) as recordcount,sum(amt) as total amount from table
union all
select count(*) as recordcount,sum(amt) as total amount from table_exception)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On