Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
JOIN vs WHERE
Message
De
17/06/2009 14:28:51
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01406428
Message ID:
01406674
Vues:
44
The query I need should get..........

For All customers.....
the number of records in crsFillRate which have EMPTY(PartOrders). If there are no records for a customer in crsFillRate, I still need a record in the result set. For the missing customers, the COUNT() can be either NULL or 0.

>Hi Rich,
>
>It's not clear what you want so I'll take a guess
>
>SELECT  cust.customer, COUNT(*) ;
>	FROM crsAllCust cust;
>		JOIN crsFillRate fr ON cust.customer = fr.custshipm ;
>	WHERE EXISTS ( SELECT 1 FROM crsFillRate fr WHERE cust.customer = custshipm AND EMPTY(PartOrders)) ;
>	GROUP BY cust.customer
>
>
>>Please Note: VFP 8
>>
>>I have a cursor (crsAllCust) with a list of customer names. There are 30 records in this table.
>>I have another cursor (crsFillRate) with some customer data in it.
>>
>>I need to join these tables to provide a count of how many records there are per customer which meet a certain criterion. I need a record returned even if there are none with a matching condition. There are three customers which have no data in crsFillRate. There are an additional two customers who have records, but without any data matching the condition.
>>
>>
>>SELECT  cust.customer, COUNT(*) ;
>>   FROM crsAllCust cust;
>>      LEFT JOIN crsFillRate fr ON cust.customer = fr.custshipm;
>>   WHERE EMPTY(fr.PartOrders);
>>   GROUP BY cust.customer
>>
>>The five "nodata" records fall out of the result. By changing the query to
>>SELECT  cust.customer, COUNT(*) ;
>>   FROM crsAllCust cust;
>>      LEFT JOIN crsFillRate fr ON cust.customer = fr.custshipm AND EMPTY(fr.PartOrders);
>>   GROUP BY cust.customer
>>
>>I get all the customers.
>>
>>I think I've had this explained to me before, but apparantly it hasn't stuck (sorry Tamar). Could somebody please give me a refresher course of what the query steps are that cause the five records to fall out of the first query?
>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform