PC Review


Reply
Thread Tools Rate Thread

Count occurrences

 
 
Lorri
Guest
Posts: n/a
 
      22nd Jan 2010
Hello all,
I am very new to Access, am doing an online course and learning as I go.
I am stuck with one query and I'm hoping someone can help me.
I have a sales table for which I am required to produce a query which tells
the most popular artists and the number of sales they have made.
The fields in the table are:-
Invoice number, product code, artist code, date, payment type.
The query is on the Artist Code field, but for the life of me I cannot get
it to show just the top 5 Artists and their sales count.
Hoping for help - written slowly 'cos I'm very new at this.
Thanks in advance.
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      22nd Jan 2010
"Lorri" <(E-Mail Removed)> wrote in message
news:7733272A-0BF7-4226-824D-(E-Mail Removed)...
> Hello all,
> I am very new to Access, am doing an online course and learning as I go.
> I am stuck with one query and I'm hoping someone can help me.
> I have a sales table for which I am required to produce a query which
> tells
> the most popular artists and the number of sales they have made.
> The fields in the table are:-
> Invoice number, product code, artist code, date, payment type.
> The query is on the Artist Code field, but for the life of me I cannot get
> it to show just the top 5 Artists and their sales count.
> Hoping for help - written slowly 'cos I'm very new at this.
> Thanks in advance.



Assuming that each record in your Sales table represents a sale for a given
artist, then first you need a totals query that returns the artist code and
the count of records for each artist code. That will be the sales count.
You can make such a query in the query designer by creating a new query
based on the Sales table. Click the "Totals" button on the toolbar (the one
with the caption that is the Greek sigma -- looks like a big, stylized "E")
to make it into a totals query. Drag the [Artist Code] to the field grid
twice. On the "Total:" row under the first column, choose "Group By", and
under the second column for the field, choose "Count". Give that field an
alias of SalesCount by changing the field name so that it looks like this:

SalesCount: [Artist Code]

At this point, if you switch into SQL view, the query's SQL looks something
like this:

SELECT [Artist Code], Count([Artist Code] As SalesCount
FROM Sales
GROUP BY [Artist Code];

If you flip into datasheet view, you'll see the raw results, ordered by
artist code.

Now, to get the top 5, we need to rank these results in descending order by
the calculated field SalesCount. Switch back to design view and on the
"Sort: row" of the field grid, under SalesData, choose "Descending". The
SQL view of the query would now look like this:

SELECT [Artist Code], Count([Artist Code] As SalesCount
FROM Sales
GROUP BY [Artist Code]
ORDER BY Count([Artist Code]) DESC;

Finally, we need just the top 5. So in design view, go to the "Top Values"
dropdown box on the toolbar and enter or choose 5. Flip to SQL view and it
should now look like this:

SELECT TOP 5 [Artist Code], Count([Artist Code] As SalesCount
FROM Sales
GROUP BY [Artist Code]
ORDER BY Count([Artist Code]) DESC;

If you switch to datasheet view, you should see that it gives you the
desired result.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count how many occurrences Sunnyskies Microsoft Excel Misc 3 17th Mar 2009 01:11 PM
Count Unique Occurrences Brandon G. Microsoft Excel Worksheet Functions 3 12th Aug 2008 12:43 PM
formula to count occurrences Libby Microsoft Excel Worksheet Functions 5 28th Mar 2008 06:07 PM
count occurrences =?Utf-8?B?UkhEMw==?= Microsoft Access 1 4th Aug 2006 06:26 PM
Count unique occurrences of name =?Utf-8?B?amhpY3N1cHQ=?= Microsoft Excel Misc 4 5th Oct 2005 05:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 PM.