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 > Ratio of count/sum

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-05-06, 12:14
arlf arlf is offline
Registered User
 
Join Date: May 2006
Posts: 16
Ratio of count/sum

DB2 v7.2 OS/390
Hello everybody.

There is a table (T1) that contains 1 record per transaction, ocurred in a group of sales units. Among others, it has the following fields:
UNIT_ID (Id of sales unit), TRANS_AMT (Trans amount).

The requirement is to calculate the total of transactions in quantity and amount by unit of sale, including the ratios (or percentages) upon the overall totals.

The next statement was used:

SELECT SELECT A.UNIT_ID, QTY, QTY / TQTY, AMT, AMT / TAMT
FROM ( SELECT UNIT_ID, COUNT(*) QTY, SUM (TRANS_AMT) AMT
FROM T1 GROUP BY UNIT_ID ) A,
( SELECT COUNT(*) TQTY, SUM (TRANS_AMT) TAMT
FROM T1 ) B
ORDER BY A.UNIT_ID

Is there a better way ?

Thanks, ARLF.
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