Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Summing on two fields in SQL
Message
 
 
À
30/05/2007 11:28:11
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01229336
Message ID:
01229339
Vues:
8
>Hi. I have a database with customer #'s and zip codes (among other things). How would I do a SQL to give me a report of unique zip codes and unique customer numbers within that zip code.
>
>I can get a listing with unique zips, but it gives me a count of all customers (not ignoring repeat customers).
>
>Thanks, Randy
Select Count(*) as CntDups, Zip, CustomerID ;
from MyTable group by 2,3 having CntDups > 1 into cursor curDups

select * from MyTable my inner join curDups dup on my.Zip = dup.zip and my.CustomerID = dup.CustomerID
Of course, these two selects can be combined into one.

For unique codes change condition to CntDups = 1 and the cursor name to curUnique

UPDATE. Looks like I misunderstood your requirements and Sergey got it right.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform