Home » SQL & PL/SQL » SQL & PL/SQL » how to use analytical function
how to use analytical function [message #627922] Tue, 18 November 2014 03:16 Go to next message
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 #627924 is a reply to message #627922] Tue, 18 November 2014 03:19 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
And the question is what exactly?
Re: how to use analytical function [message #627925 is a reply to message #627924] Tue, 18 November 2014 03:22 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi cookiemonster, please check the below..
select * from test 

Ref_id    cust_id  Amount
-------   -------  ------
1           1        100
1           1        100
2           1         50

Expected Result

cust_id  Amount
-------  ------
1        250
Re: how to use analytical function [message #627927 is a reply to message #627925] Tue, 18 November 2014 03:23 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Use aggregate sum
Re: how to use analytical function [message #627928 is a reply to message #627922] Tue, 18 November 2014 03:24 Go to previous messageGo to next message
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

Re: how to use analytical function [message #628049 is a reply to message #627925] Wed, 19 November 2014 09:26 Go to previous messageGo to next message
sandeep_orafaq
Messages: 88
Registered: September 2014
Member
you question says: Quote:
" how to use analytical function"

why do you need analytical function for just doing a simple aggregation?

[Updated on: Wed, 19 November 2014 09:26]

Report message to a moderator

Re: how to use analytical function [message #628054 is a reply to message #628049] Wed, 19 November 2014 09:47 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Because everyone knows that analytic functions are better than anything to do anything... Laughing

[Updated on: Wed, 19 November 2014 09:48]

Report message to a moderator

Previous Topic: how to get the previous value in the loop into, 2 separate variable without overwriting
Next Topic: materialized view log size doesn't correlate with its rows quantity
Goto Forum:
  


Current Time: Fri Apr 19 20:49:31 CDT 2024