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.
|
|
0
|
|
|
|
Reply
|
Utf
|
1/22/2010 6:47:01 PM |
|
"Lorri" <Lorri@discussions.microsoft.com> wrote in message
news:7733272A-0BF7-4226-824D-0AAC25F7B2C7@microsoft.com...
> 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)
|
|
0
|
|
|
|
Reply
|
Dirk
|
1/22/2010 7:15:12 PM
|
|
|
1 Replies
503 Views
(page loaded in 0.202 seconds)
Similiar Articles: Counting Occurrence of a Value within Cells - microsoft.public ...I have a user who is using Excel as a database – ugh. One of their columns (fields) has contact data points. As an example, a cell might state – “... counting identical items in a column and returning the occurrences ...I use excell 2000. I have one column with 700 rows. In each cell is one number, either a 0, 1, 2, 3, 4, or 5. In the second column I have five rows,... Counting occurences with multiple entries - microsoft.public.excel ...Date Range Entry - microsoft.public.access.forms Counting occurences with multiple entries - microsoft.public.excel ... Count occurrences of values or unique values in a ... counting occurences specific month appears - microsoft.public ...I have been trying to use SUMPRODUCT but that only seems to count occurences. ... what formula to use to count the occurrences ... excel: count occurrence in current month.? Count a string withing a string - VBA - microsoft.public.access ...Count a string withing a string - VBA ... macro to count the occurrences of a specific character in a ... value So =LEN(A2)-LEN ... Re: Count occurrence of character ... counting the number of occurences - microsoft.public.excel ...Counting Occurrence of a Value within Cells - microsoft.public ... counting the number of occurences - microsoft.public.excel ... Counting Occurrence of a Value within ... Unique Values, not Unique Records - microsoft.public.excel.misc ...Count occurrences of values or unique values in a data range ... Show All Hide All Let's say you want to find out how many unique values ... then click a blank column ... Counting Text Occurances - HELP PLEASE - microsoft.public.excel ...How to count the occurrences of a number or text in a range in Excel To enter an array formula, press CTRL+SHIFT+ENTER. How to Count the Occurrences of a Text ... How to list and count unique records - microsoft.public.excel ...Count occurrences of values or unique values in a data range ... Select the Unique records only check box, and click OK. The unique values from ... count text occurance in range - microsoft.public.excel.worksheet ...Countif formula for specific text within range - microsoft.public ... How to count the ... Counting Occurrence of a Value within Cells - microsoft.public ... How to: Count Occurrences of a Word in a String (LINQ)This example shows how to use a LINQ query to count the occurrences of a specified word in a string. Note that to perform the count, first the Char[]) method is ... Description of formulas to count the occurrences of text ...Provides examples to describe formulas that calculate the number of occurrences of text, characters, and words. Count Occurrences: If CasesCount Occurrences: If Cases. The If Cases dialog box allows you to count occurrences of values for a selected subset of cases, using conditional expressions. Count occurrences of a substring - Rosetta CodeCount occurrences of a substring You are encouraged to solve this task according to the task description, using any language you may know. Formulas to count the occurrences of text, characters, or words in ...This article contains formulas that calculate the following: The number of occurrences of a text string in a range of cells. The number of occurrences of a ... 7/14/2012 11:12:43 AM
|