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 > Pgsql Sql > subselect with ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 3420 of 3559
Post > Topic >>

subselect with group by

by "Andreas Sakowski" <news@[EMAIL PROTECTED] > Apr 18, 2008 at 03:01 PM

create table bla1 (
  id serial not null primary key
  , anzahl int not null
) ;

insert into bla1 ( anzahl ) values ( 1 ) , ( 2 ) , ( 3 ) ;

create table bla2 (
  id serial not null primary key
  , aktuell bool not null
  , bla1id int not null references bla1
  , anzahl int not null
) ;

insert into bla2 ( aktuell , bla1id , anzahl ) values
  ( 'f' , 1 , 1 )  , ( 'f' , 2 , 1 )  , ( 't' , 3 , 1 ) ;

select
  case when aktuell then bla1id else 0 end
from bla2
group by
  case when aktuell then bla1id else 0 end ;

 case
------
    0
    3
(2 Zeilen)

select
  case when aktuell then bla1id else 0 end
  , sum( anzahl )
    , (
      select
        sum( anzahl )
      from bla1
      where
        id = case when aktuell then bla1id else 0 end
    )
from bla2
group by
  case when aktuell then bla1id else 0 end ;

FEHLER:  Unteranfrage verwendet nicht gruppierte
Spalte »bla2.aktuell« aus äußerer Anfrage

PostgreSQL 8.3.1 on i486-pc-linux-gnu,
compiled by GCC cc (GCC) 4.2.3 (Debian 4.2.3-2)

why can i not use the expression from the group by
in the subselect?

Thank you for your answers
Andreas
 




 1 Posts in Topic:
subselect with group by
"Andreas Sakowski&qu  2008-04-18 15:01:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan13V112 Sun Jul 6 21:54:41 CDT 2008.