how to use analytical function [message #627922] |
Tue, 18 November 2014 03:16 |
|
mist598
Messages: 1195 Registered: February 2013 Location: Hyderabad
|
Senior Member |
|
|
Hi all,
I have data like below in the Table
select * from test
Ref_id cust_id Amount
------- ------- ------
1 1 100
1 1 100
2 1 50
cust_id Amount
------- ------
1 250
|
|
|
|
|
|
Re: how to use analytical function [message #627928 is a reply to message #627922] |
Tue, 18 November 2014 03:24 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
mist598 wrote on Tue, 18 November 2014 14:46
cust_id Amount
------- ------
1 250
Is this your expected output?
Just use SUM and GROUP BY. you just need to aggregate.
SQL> WITH DATA AS(
2 SELECT 1 cust_id, 100 amount FROM dual UNION ALL
3 SELECT 1, 100 FROM dual UNION ALL
4 SELECT 1, 50 FROM dual)
5 SELECT cust_id, sum(amount) total_amount
6 FROM DATA
7 GROUP BY cust_id
8 /
CUST_ID TOTAL_AMOUNT
---------- ------------
1 250
SQL>
[Updated on: Tue, 18 November 2014 03:25] Report message to a moderator
|
|
|
|
|