Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: SQL BrainTeaser
jAnO! <j.j.groot_at_kpn.com> schreef in artikel
<01c0fa33$044c01a0$142b15ac_at_TONTW0102131521>...
>
>
> Krisss <kmbotha_at_netinfo.ubc.ca> schreef in artikel
> <3b31b734.187723645_at_news.interchange.ubc.ca>...
> > Hi all,
> >
> > Using Oracle, I'm trying to analyze a table of the form:
> >
> > id1 id2 value
> > ---------------------------------
> > aa a1 4
> > bb a2 3
> > cc a1 6
> > dd a3 8
> > ee a4 10
> > ff a4 10
> >
> > What I'd like to do is combine rows that have the same id2 (by summing
> > their value). i.e. I want to get is THIS table:
> > id2 value
> > ------------------------------
> > a1 10
> > a2 3
> > a3 8
> > a4 20
> >
> > any ideas on how I should go about this using SQL??
> >
> > Thanks
> > ~~====----..----====~~
> > Kris Botha
> >
> >
>
> select id2, sum(value) from table
> group by id2;
>
> hth
>
> Jan
>
extra:
if you want to create a table:
create table name1 as select id2 alias1, sum(value) alias2 from table group by id2; Received on Thu Jun 21 2001 - 04:36:45 CDT