Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Flag for a value in a list
Message
De
15/01/2000 07:10:22
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
14/01/2000 17:03:50
Michael Dougherty
Progressive Business Publications
Malvern, Pennsylvanie, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00318140
Message ID:
00318517
Vues:
27
>>select distinct rep, .t. as SA_flag from myTable ; where pub = "SA" ;union ;
>select distinct rep, .f. as SA_flag from myTable ;
> where rep not in (select distinct rep from myTable where pub="SA") ;order by 1
>
>Assuming a significant size "myTable", how would that statement compare with:
>Select distinct rep, .t. as SA_Flag from myTable where pub="SA";
>union;
>Select distinct rep, .f. as SA_Flag from myTable where NOT (pub="SA")
>
>It seems the first statement would be querying the same set twice.
>
>I thought there was an "in-line" way to get a unique value from a group, but i guess the two-step union will work (almost) as effectively.


Michael,
I thought it but I think it won't work. Why, because there could be records with pub # "SA" with same rep those having pub="SA". Union wouldn't handle it becuse of the unmatching SA_Flag.
rep   pub
---   ---
1     
1     SA
1
2
3
4     SA
4
5
5     SA

*would produce
rep   SA_Flag
---   ---
1     .T.
1     .F.
2     .F.
3     .F.
4     .T.
4     .F.
5     .T.
5     .F.
For performance and one pass there could be other clever SQLs :) Like :
Select rep, iif(sum(iif(pub="SA",1,0))>0,.t.,.f.) as SA_Flag ;
 from myTable ;
 group by 1
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform