mer. 31 juillet 2013, 18h45

FoxInCloud (Th. Nivelet)
France
atoutfox.public.association
Re: SELECT ... Count(distinct ...), Count(distinct ...) ... : DISTINCT is invalid.
Merci Me Gregory
Pas bien compris le raisonnement sous-jacent aux requêtes au tu proposes, je me pencherai dessus plus attentivement demain matin.
à première lecture,
- la disparition de parent m'interpelle
- je ne trouve pas d'outer join
- pk cast(... as B(0)) et non cast(... as I)
j'y verrai probablement plus clair demain!
Merci en tous cas...
Le mer. 31 juillet 2013, 14h27 Gregory Adam a écrit :
> Bon,
>
> 2 problemes
>
> (1) Distinct is invalid >> max une clause distinct
> (2) S'il n'y a pas d'enfants dans child1 et/ou child2 pour un certain pk ton inner join ne retournera AUCUNE ligne (mets un return juste après create cursor child2 (fk I, data I) ) et regarde le resultat
>
> Donc, pour remedier a ces deux problemes, il faut (A) deux requites et (B) les joindre par un outer join
>
&& tous
select nvl(Q1.fk, Q2.fk) as pk, ;
cast( nvl(Q1.child1_cnt, 0) as B(0)) as child1_cnt, ;
cast( nvl(Q2.child2_cnt, 0) as B(0)) as child2_cnt ;
from ( select fk, ;
count(distinct data) as child1_cnt ;
from child1 ;
group by 1;
) Q1 ;
full join ;
( select fk, ;
count(distinct data) as child2_cnt ;
from child2 ;
group by 1;
) Q2 ;
on (Q2.fk == Q1.fk) ;
into cursor tmp_all
&& pk 1
select nvl(Q1.fk, Q2.fk) as pk, ;
cast( nvl(Q1.child1_cnt, 0) as B(0)) as child1_cnt, ;
cast( nvl(Q2.child2_cnt, 0) as B(0)) as child2_cnt ;
from ( select fk, ;
count(distinct data) as child1_cnt ;
from child1 ;
group by 1;
where ( fk == 1 ) ;
) Q1 ;
full join ;
( select fk, ;
count(distinct data) as child2_cnt ;
from child2 ;
group by 1;
where (fk = 1) ;
) Q2 ;
on (Q2.fk == Q1.fk) ;
into cursor tmp_1
>
>
> .
>
Permalink : http://www.atoutfox.org/nntp.asp?ID=0000012688