Ferruccio73
New member
- Local time
- Today, 10:07
- Joined
- Oct 27, 2009
- Messages
- 4
I wrote the query below, but it's taking over an hour to complete. I understand that access does not have the count(distinct x) function, so I was lead down this path. Any idea if this is wrong or if I can improve its performance. Any assistance would be greatly appreciated.
The table looks something like this:
Amount, PO_Num,VendorName
$2000,1234,ABC
$3000,1234,ABC
$4000,1200,ABC
$6000,4321,BAC
$1000,4300,BAC
$2000,3214,CAB
What I'm trying to do is get a list of Vendors and the number of purchase orders they have over $2500.
It should return something like:
Vendor,Number_Of_POs
ABC,2
BAC,1
SELECT A.VendorName AS Vendor, Count(B.PO_Num) As Number_Of_POs
FROM Data AS A,(Select Distinct PO_Num, VendorName from Data) as B
GROUP BY A.VendorName
HAVING SUM(A.Amount)>2500
ORDER BY Count(B.PO_Num) Desc;
Any help is greatly appreciated.
The table looks something like this:
Amount, PO_Num,VendorName
$2000,1234,ABC
$3000,1234,ABC
$4000,1200,ABC
$6000,4321,BAC
$1000,4300,BAC
$2000,3214,CAB
What I'm trying to do is get a list of Vendors and the number of purchase orders they have over $2500.
It should return something like:
Vendor,Number_Of_POs
ABC,2
BAC,1
SELECT A.VendorName AS Vendor, Count(B.PO_Num) As Number_Of_POs
FROM Data AS A,(Select Distinct PO_Num, VendorName from Data) as B
GROUP BY A.VendorName
HAVING SUM(A.Amount)>2500
ORDER BY Count(B.PO_Num) Desc;
Any help is greatly appreciated.