Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 11th, 2008, 05:15 AM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default Top percent Query acting strangely in access 2002

Hi All,

Hoping you can help me with an issue I'm having with a query. I need to find the apr offered to 67% or more of cases in ascending order by our suppliers. The SQL is given below:

SELECT TOP 67 PERCENT lkpqryarname.arname, tblfileinspect.caseapr
FROM tblfileinspect INNER JOIN lkpqryarname ON tblfileinspect.arfirm = lkpqryarname.arid
WHERE (((tblfileinspect.caseapr) Is Not Null And (tblfileinspect.caseapr)>1) AND ((tblfileinspect.ffdate) Between Date() And Date()-90))
GROUP BY lkpqryarname.arname, tblfileinspect.caseapr;

The problem is that it is only bringing back a maximum of 15 of the 40 arnames that are actually there. The TOP 67 percent is working because when i put in the field caseapr it shows them correctly for less firms.

I have added max to the caseapr field and it still gives the same correct figure. I just need to get all the firms out of the query. That changes to the following and I only get 7 results:

SELECT TOP 67 PERCENT lkpqryarname.arname, Max(tblfileinspect.caseapr) AS MaxOfcaseapr
FROM tblfileinspect INNER JOIN lkpqryarname ON tblfileinspect.arfirm = lkpqryarname.arid
WHERE (((tblfileinspect.caseapr) Is Not Null And (tblfileinspect.caseapr)>1) AND ((tblfileinspect.ffdate) Between Date() And Date()-90))
GROUP BY lkpqryarname.arname;

If I add ascending to the caseapr i get a totally different set of figures.

I've tried altering the date to cover a two year period and the only thing that changes is the value in the caseapr field. There are over 900 records to sort through and some do not have dates in as they were entered for other reasons.

 
Old January 11th, 2008, 01:33 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

In the last paragraph you state that some records do not have dates. Is that in this field: tblfileinspect.ffdate ?

If so, in the case where you are showing only 15 of 40 records, are the missing records also missing dates?



mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old January 11th, 2008, 01:38 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Also, if you "need to find the apr offered to 67% or more of cases in ascending order," it seems to me you would want to take the total of your suppliers, and then multiply by .67, then do a

Select Count(Supplier) >= (.67 integer), apr, group by apr

and that would show you in every case where an apr was offered to .67% or more of your suppliers, and what that apr was.


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old January 11th, 2008, 02:33 PM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your replies so far.

Ok to clarify things a little bit.

Each supplier (arname) submits a loan case for inspection (tblfileinspect) which contains an APR (caseapr). Now in order for the supplier to be able to advertise they need to show what 67% or more of their customers - loan cases - receive for an APR depending on other factors within a certain time period or ever. Therefore the fact that the dates are missing isn't important on older cases which are the ones that are missing.

Hence need to know for each supplier the 67th result e.g. 200 cases the APR required would be the 134th. The APRs need to be ordered ascending. It doesn't matter, using the example of the 134th case, if the preceeding 3 entries and 2 after are the same or different.

I need to find the 67% or more for various other figures the suppliers give in so need to figure out what I've done wrong.

The bizarre thing is this task is a doddle - less than a min job - to do with excel just a pain with access. Just need access for the scale and other analytics that need to be done.

 
Old January 15th, 2008, 09:27 AM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've realised what the code is doing, just can't think of the solution to it and tried numerous sub query permutations to get it to behave.

Its either sorting the top 67% results of all suppliers or its sorting the top 67% of aprs instead of grouping by supplier then sorting the apr for each.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Upgrading from Access 2002 to Access 2003 lryckman Access 1 July 16th, 2006 01:46 AM
Insert into error with union query in Access 2002 roniestein Access 8 December 21st, 2004 07:47 PM
Join Query Distinct and Top 1 ahanson SQL Language 4 November 30th, 2004 01:29 PM
header() acting strangely.... Snib Pro PHP 5 July 15th, 2004 01:41 PM
Query to populate top users flyin ADO.NET 2 April 2nd, 2004 11:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.