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


|