Write a query total amount based on item and cost? [Resolved]

Posted by Rajesh123 under Oracle on 8/19/2015 | Points: 10 | Views : 2217 | Status : [Member] | Replies : 3
items      cost     totalamount
abc        
100        1000
pqr        
200        2000
abc        
100        4000
def        300        3000
abc        
100        3000


rajesh.plsql123@gmail.com


Responses

Posted by: Bandi on: 8/20/2015 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
SELECT items,cost, SUM(totalamount) as TotalAmount
FROM
TableName
GROUP BY items
, cost


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Rajesh123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajesh123 on: 8/20/2015 [Member] Starter | Points: 25

Up
0
Down
hi bandi
any way thanks
but i want like below output
select * from orders;

ITEM             COST TOTALAMOUNT
---------- ---------- -----------
abc              
100        1000
cde              
200        2000
abc              
100        4000
bjh              
200        5000

OUTPUT query.
SQL> SELECT ITEM,COST,TOTALAMOUNT FROM ORDERS
 
2  UNION ALL
 
3  SELECT NULL,NULL,SUM(TOTALAMOUNT) FROM ORDERS;


ITEM             COST  TOTALAMOUNT
---------- ---------- -----------
abc              
100        1000
cde              
200        2000
abc              
100        4000
bjh              
200        5000
                             
12000


rajesh.plsql123@gmail.com

Rajesh123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/20/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
check ROLLUP in Oracle.. It gives you the required output...

check ROLLUP section in the link
https://oracle-base.com/articles/misc/rollup-cube-grouping-functions-and-grouping-sets

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Rajesh123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response