Subject | Re: SQL question |
---|---|
Author | Ali Gökçen |
Post date | 2005-09-09T10:29:11Z |
Hmm,
i just tested, firebird doesn't force
the group column to be in select list (1.5.3) But my brain needs
lunch to correct remember and work..
So you don't need sub-subselect, just delete the ty column.
...
(select First 1 sum(amount) from test group by ty) as GROUPSUM1,
...
-Ali
P.S. Firebird people, i'm sorry about too much emails, i will not
read-write emails anymore when i hungry. :P
--- In firebird-support@yahoogroups.com, Ali Gökçen <alig@e...>
wrote:
i just tested, firebird doesn't force
the group column to be in select list (1.5.3) But my brain needs
lunch to correct remember and work..
So you don't need sub-subselect, just delete the ty column.
...
(select First 1 sum(amount) from test group by ty) as GROUPSUM1,
...
-Ali
P.S. Firebird people, i'm sorry about too much emails, i will not
read-write emails anymore when i hungry. :P
--- In firebird-support@yahoogroups.com, Ali Gökçen <alig@e...>
wrote:
> but you may be try this:test
>
> Select
> (select sum(amount) from test where ty=(select first 1 ty from
> group ty))as
> as GROUPSUM1,
> ...
>
> -Ali
>
> --- In firebird-support@yahoogroups.com, Ali Gökçen <alig@e...>
> wrote:
> > Ops! sorry,
> > you can't select more than one column in subselects.
> >
> > -Ali
> >
> > --- In firebird-support@yahoogroups.com, Ali Gökçen <alig@e...>
> > wrote:
> > > Hi Michael,
> > > As you know, there is no row# limit about your group but
> > > tables and selects have column# limit.
> > >
> > > Anyway,
> > > You can turn your rows 90 degree with some ways if u sure about
> > > group limit..
> > >
> > > Select
> > > (select First 1 ty,sum(amount) from test group by ty) as
> GROUPSUM1,
> > > (select First 1 skip 1 ty,sum(amount) from test group by ty)
> > > GROUPSUM2,same
> > > from rdb$database
> > >
> > > ( i didn't test it but worked theorically in my untheareded
> single
> > > proccessed brain ;) )
> > >
> > > or you can write a selectable stored procedure and suspend
> > > rows as columns..
> > >
> > > Regards,
> > >
> > > -Ali
> > >
> > > --- In firebird-support@yahoogroups.com, "Michael Vilhelmsen"
> > > <Michael.Vilhelmsen@M...> wrote:
> > > > Hi
> > > >
> > > > Lets say I have a table defined as:
> > > >
> > > > CREATE TABLE TEST (
> > > > TY INTEGER,
> > > > AMOUNT NUMERIC(15,2) DEFAULT 0);
> > > >
> > > > If this contains this:
> > > >
> > > > 0,100
> > > > 1,200
> > > > 0,200
> > > > 1,300
> > > > 0,300
> > > >
> > > > An SQL statement like
> > > >
> > > > Select
> > > > ty,
> > > > SUM(Amount)
> > > > from Test
> > > > Group by
> > > > ty
> > > >
> > > > gives me this:
> > > >
> > > > 0,600
> > > > 1,500
> > > >
> > > >
> > > > Can I make an SQL that returns something like this:
> > > >
> > > > 600,500
> > > >
> > > > In short - I would like to have both SUM returned on the
> > > line...
> > > >
> > > >
> > > > Regards
> > > > Michael