Query Help

G

Guest

I have a list that stores an agent name and premium per policy. I want to
find the top selling agent within the last 7 days. I got the last 7 days
part but how do I only get 1 record. I just want the results to be one agent
name and the premium. Here is the sql.

SELECT ALLPolicies.Agent, Sum(ALLPolicies.AnnualPremium) AS SumOfAnnualPremium
FROM ALLPolicies
GROUP BY ALLPolicies.Agent, ALLPolicies.BoundDate
HAVING (((ALLPolicies.BoundDate)>=Date()-7))
ORDER BY Sum(ALLPolicies.AnnualPremium);
 
G

Guest

Try this ---
SELECT TOP 1 ALLPolicies.Agent, Sum(ALLPolicies.AnnualPremium) AS
SumOfAnnualPremium
FROM ALLPolicies
GROUP BY ALLPolicies.Agent, ALLPolicies.BoundDate
HAVING (((ALLPolicies.BoundDate)>=Date()-7))
ORDER BY Sum(ALLPolicies.AnnualPremium) DESC;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top