Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Oracle Miscellaneous > Re: Query using...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 6852 of 7280
Post > Topic >>

Re: Query using group

by Prasath <prasath.rao@[EMAIL PROTECTED] > Apr 23, 2008 at 05:57 AM

On Apr 23, 1:50 pm, Ed Prochak <edproc...@[EMAIL PROTECTED]
> wrote:
> On Apr 23, 7:35 am, Prasath <prasath....@[EMAIL PROTECTED]
> wrote:
>
>
>
> > i have a table with 4 columns,  they look like
>
> > currency1 currency2 amt1 amt2
> > =======================
> > USD   GBP   10    9
> > GBP   USD    5    8
> > JPY    INR    20    7
> > INR      JPY 14    100
>
> > i want to cross add the amounts for each group of currency1 and
> > currency2.  now, the currency groups are bit unusal.    For example,
> > the first two rows in the above table fall under the group USD+GBP (or
> > GBP+USD, the other does not matter)
>
> > the result should look like
>
> > currency1 currency2 sum1 sum2
> > USD GBP 18 14 (from 10+8 and 9+5)
> > INR JPY 120 21 (from 20+100 and 14+7)
>
> > any ideas?
>
> what have you tried?
> I can imagine a simple UNION may help. Then you will need a way to
> weed out the "duplicates", e.g.
> USD GBP 18 14
> GBP USD 14 18
> Show us what you tried and then we can help.
> (This is to avoid doing someone's homework for them.)
>
> Awaiting your reply,
>    ed

the below query works.

select LEAST(currency1,currency2) first, GREATEST(currency1,currency2)
second,
SUM(case when currency1 = greatest(currency1,currency2) then amt1 else
amt2 end) amt1,
SUM(case when currency1 = least(currency1,currency2) then amt1 else
amt2 end) amt2
from test
group by LEAST(currency1,currency2), GREATEST(currency1,currency2)
 




 3 Posts in Topic:
Query using group
Prasath <prasath.rao@[  2008-04-23 05:35:58 
Re: Query using group
Ed Prochak <edprochak@  2008-04-23 05:50:31 
Re: Query using group
Prasath <prasath.rao@[  2008-04-23 05:57:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 0:39:19 CST 2008.