Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Join with 2 COUNT( ) columns
Message
From
04/04/2001 19:03:07
 
 
To
04/04/2001 14:22:05
Adam Skowronski
Custom Designed Systems
Miami, Florida, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00492027
Message ID:
00492142
Views:
22
>I'm trying to create a query giving the total orders by zipcodes. This in itself is easy, but I wish to have the totals for the Billing & Delivery zipcodes, displayed by zipcode. The data is two tables (BillingInfo & OrderData) respectfully.
>
>Here is my code which gives me the same totals for both counts, oZipCnt and bZipCnt.
>
>
>SELECT 	COUNT(o.zip) AS oZipCnt,
>	o.zip AS oZip,
>	o.deliverydate,
>	COUNT(b.zip) AS bZipCnt,
>	b.zip AS bZip
>FROM [OrderData] o, [BillingInfo] b
>WHERE (o.zip = b.zip AND o.deliverydate >= ldDate)
>GROUP BY deliverydate, o.Zip, b.Zip
>
>
>I am not very familiar with JOIN's, and that is more than likely where my problem stems from. Any help is appreciated.

I'm reading your requirements differently from the way Nadya did - and I've been wrong before doing that. I think you want to know how many orders were received for each zip code and how many deliveries were made into each zip code. FWIW, here's my solution
SELECT o.deliverydate,o.zip,00001 AS oZipCount,00000 as bZipCount;
  FROM [OrderData] o;
  WHERE o.deliverydate >= ldDate;
UNION ALL;
SELECT b.billingdate,b.zip,00000,00001;
  FROM [BillingInfo] b;
  WHERE b.billingdate >= ldDate;
INTO CURSOR curFirst

SELECT deliverydate,zip,SUM(oZipCount),SUM(bZipCount);
  FROM curFirst;
  GROUP BY 1,2
Hope this is what you needed.......Rich
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform