A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to get rank numbers for Top results



 
 
Thread Tools Display Modes
  #1  
Old September 9th, 2004, 11:34 PM
BG
external usenet poster
 
Posts: n/a
Default How to get rank numbers for Top results

Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week and sort
them by dollars. The query works but I don't know how to
show ranking for each row in a seperate column. like 1st,
2nd, 3rd etc.
Can anyone please help.
Thanks
  #2  
Old September 10th, 2004, 12:18 AM
Tom Ellison
external usenet poster
 
Posts: n/a
Default

Dear BG:

If have found the best way to help someone with this question is to
have them post the query the have now that shows the results they want
but without the Rank column. It should sort the results so the #1
ranking row is at the top.

Please be advised that the results may show ties, and will do so as
they would be in a horse race. If two horses finish tied for first,
the next horse is in 3rd place, and there is no 2nd place. OK?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 15:34:25 -0700, "BG" wrote:

Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week and sort
them by dollars. The query works but I don't know how to
show ranking for each row in a seperate column. like 1st,
2nd, 3rd etc.
Can anyone please help.
Thanks


  #3  
Old September 10th, 2004, 12:33 AM
BG
external usenet poster
 
Posts: n/a
Default

Yes it's OK if there's a tie.

here's my query. Please let me know if this is what you
asked me to post. Thanks for your help.
-------------------
SELECT TOP 25 vw_sell_thru.week_ending,
vw_sell_thru.account, vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru INNER JOIN dbo_vw_MM_MATERIAL ON
vw_sell_thru.material = dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT ON
dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE (((dbo_vw_MM_MATERIAL.DEPARTMENT)="01"))
GROUP BY vw_sell_thru.week_ending, vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
HAVING (((vw_sell_thru.week_ending)=[week_ending_date]))
ORDER BY vw_sell_thru.last_wk_sls DESC;



-----Original Message-----
Dear BG:

If have found the best way to help someone with this

question is to
have them post the query the have now that shows the

results they want
but without the Rank column. It should sort the results

so the #1
ranking row is at the top.

Please be advised that the results may show ties, and

will do so as
they would be in a horse race. If two horses finish

tied for first,
the next horse is in 3rd place, and there is no 2nd

place. OK?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 15:34:25 -0700, "BG"

wrote:

Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week and

sort
them by dollars. The query works but I don't know how

to
show ranking for each row in a seperate column. like

1st,
2nd, 3rd etc.
Can anyone please help.
Thanks


.

  #4  
Old September 10th, 2004, 12:42 AM
Ed
external usenet poster
 
Posts: n/a
Default

I've done something similar before by outputting to a table with an
autonumber field.

--
Ed

Remove the capital ST spam trap
when replying directly to me.


"BG" wrote in message
...
Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week and sort
them by dollars. The query works but I don't know how to
show ranking for each row in a seperate column. like 1st,
2nd, 3rd etc.
Can anyone please help.
Thanks



  #5  
Old September 10th, 2004, 05:40 PM
Tom Ellison
external usenet poster
 
Posts: n/a
Default

Dear MBGonul:

SELECT TOP 25 vw_sell_thru.week_ending, vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2 ,
(SELECT COUNT(*) + 1 FROM vw_sell_thru T1
WHERE T1.last_wk_sls vw_sell_thru.last_wk_sls) AS Rank
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru
INNER JOIN dbo_vw_MM_MATERIAL
ON vw_sell_thru.material = dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT
ON dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
GROUP BY vw_sell_thru.week_ending, vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
HAVING (vw_sell_thru.week_ending) = [week_ending_date]
ORDER BY vw_sell_thru.last_wk_sls DESC;

I have added the Rank column as the last one. Since this is a SELECT
INTO the actual position of the Rank column will have to match the
Rank column in the destination table, which I couldn't know.

Since you have ordered the results descending, I have created the
ranking so the largest value will be ranked #1. This is an
assumption, and if it is not correct, change the in my additional
column to be .

Please let me know if this helped and if I can be of any other
assistance.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 16:33:34 -0700, "BG" wrote:

Yes it's OK if there's a tie.

here's my query. Please let me know if this is what you
asked me to post. Thanks for your help.
-------------------
SELECT TOP 25 vw_sell_thru.week_ending,
vw_sell_thru.account, vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru INNER JOIN dbo_vw_MM_MATERIAL ON
vw_sell_thru.material = dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT ON
dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE (((dbo_vw_MM_MATERIAL.DEPARTMENT)="01"))
GROUP BY vw_sell_thru.week_ending, vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
HAVING (((vw_sell_thru.week_ending)=[week_ending_date]))
ORDER BY vw_sell_thru.last_wk_sls DESC;



-----Original Message-----
Dear BG:

If have found the best way to help someone with this

question is to
have them post the query the have now that shows the

results they want
but without the Rank column. It should sort the results

so the #1
ranking row is at the top.

Please be advised that the results may show ties, and

will do so as
they would be in a horse race. If two horses finish

tied for first,
the next horse is in 3rd place, and there is no 2nd

place. OK?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 15:34:25 -0700, "BG"

wrote:

Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week and

sort
them by dollars. The query works but I don't know how

to
show ranking for each row in a seperate column. like

1st,
2nd, 3rd etc.
Can anyone please help.
Thanks


.


  #6  
Old September 10th, 2004, 07:05 PM
BG
external usenet poster
 
Posts: n/a
Default

Hi Tom - I ran the query and the result didn't come as
expected. the first rank I get is 2 then 8,
45,47,60....and the last one is 468...
Any idea why it might have come that way?


-----Original Message-----
Dear MBGonul:

SELECT TOP 25 vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2 ,
(SELECT COUNT(*) + 1 FROM vw_sell_thru T1
WHERE T1.last_wk_sls vw_sell_thru.last_wk_sls)

AS Rank
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru
INNER JOIN dbo_vw_MM_MATERIAL
ON vw_sell_thru.material =

dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT
ON dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
GROUP BY vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2
HAVING (vw_sell_thru.week_ending) = [week_ending_date]
ORDER BY vw_sell_thru.last_wk_sls DESC;

I have added the Rank column as the last one. Since

this is a SELECT
INTO the actual position of the Rank column will have to

match the
Rank column in the destination table, which I couldn't

know.

Since you have ordered the results descending, I have

created the
ranking so the largest value will be ranked #1. This is

an
assumption, and if it is not correct, change the in my

additional
column to be .

Please let me know if this helped and if I can be of any

other
assistance.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 16:33:34 -0700, "BG"

wrote:

Yes it's OK if there's a tie.

here's my query. Please let me know if this is what you
asked me to post. Thanks for your help.
-------------------
SELECT TOP 25 vw_sell_thru.week_ending,
vw_sell_thru.account, vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru INNER JOIN dbo_vw_MM_MATERIAL ON
vw_sell_thru.material = dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT ON
dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE (((dbo_vw_MM_MATERIAL.DEPARTMENT)="01"))
GROUP BY vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
HAVING (((vw_sell_thru.week_ending)=[week_ending_date]))
ORDER BY vw_sell_thru.last_wk_sls DESC;



-----Original Message-----
Dear BG:

If have found the best way to help someone with this

question is to
have them post the query the have now that shows the

results they want
but without the Rank column. It should sort the

results
so the #1
ranking row is at the top.

Please be advised that the results may show ties, and

will do so as
they would be in a horse race. If two horses finish

tied for first,
the next horse is in 3rd place, and there is no 2nd

place. OK?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 15:34:25 -0700, "BG"

wrote:

Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week and

sort
them by dollars. The query works but I don't know how

to
show ranking for each row in a seperate column. like

1st,
2nd, 3rd etc.
Can anyone please help.
Thanks

.


.

  #7  
Old September 10th, 2004, 07:25 PM
Tom Ellison
external usenet poster
 
Posts: n/a
Default

Dear BG:

That would be because I missed the filter.

SELECT TOP 25 vw_sell_thru.week_ending, vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2 ,
(SELECT COUNT(*) + 1 FROM vw_sell_thru T1
INNER JOIN dbo_vw_MM_MATERIAL
ON T1.material = dbo_vw_MM_MATERIAL.MATERIAL
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
AND T1.last_wk_sls vw_sell_thru.last_wk_sls) AS Rank
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru
INNER JOIN dbo_vw_MM_MATERIAL
ON vw_sell_thru.material = dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT
ON dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
GROUP BY vw_sell_thru.week_ending, vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
HAVING (vw_sell_thru.week_ending) = [week_ending_date]
ORDER BY vw_sell_thru.last_wk_sls DESC;

This is getting fairly complex. I hope I haven't had too much trouble
fixing it up properly. It's not always easy for me.

So, what it was doing was to calculate the Rank using every row in
vw_sell_thru, whereas it needs to use only those rows where the joined
row of dbo_ww_MM_MATERIAL has Department 01. It was apparently
finding a number of rows to count from that table that you wanted to
exclude. Sorry, missed that, but it's obvious given the problem you
had. Your description was just what I needed to know to see what I
had missed.

Hope this is much better. And I hope this isn't getting too complex
for Jet.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Fri, 10 Sep 2004 11:05:25 -0700, "BG"
wrote:

Hi Tom - I ran the query and the result didn't come as
expected. the first rank I get is 2 then 8,
45,47,60....and the last one is 468...
Any idea why it might have come that way?


-----Original Message-----
Dear MBGonul:

SELECT TOP 25 vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2 ,
(SELECT COUNT(*) + 1 FROM vw_sell_thru T1
WHERE T1.last_wk_sls vw_sell_thru.last_wk_sls)

AS Rank
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru
INNER JOIN dbo_vw_MM_MATERIAL
ON vw_sell_thru.material =

dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT
ON dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
GROUP BY vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2
HAVING (vw_sell_thru.week_ending) = [week_ending_date]
ORDER BY vw_sell_thru.last_wk_sls DESC;

I have added the Rank column as the last one. Since

this is a SELECT
INTO the actual position of the Rank column will have to

match the
Rank column in the destination table, which I couldn't

know.

Since you have ordered the results descending, I have

created the
ranking so the largest value will be ranked #1. This is

an
assumption, and if it is not correct, change the in my

additional
column to be .

Please let me know if this helped and if I can be of any

other
assistance.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 16:33:34 -0700, "BG"

wrote:

Yes it's OK if there's a tie.

here's my query. Please let me know if this is what you
asked me to post. Thanks for your help.
-------------------
SELECT TOP 25 vw_sell_thru.week_ending,
vw_sell_thru.account, vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru INNER JOIN dbo_vw_MM_MATERIAL ON
vw_sell_thru.material = dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT ON
dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE (((dbo_vw_MM_MATERIAL.DEPARTMENT)="01"))
GROUP BY vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material, dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
HAVING (((vw_sell_thru.week_ending)=[week_ending_date]))
ORDER BY vw_sell_thru.last_wk_sls DESC;



-----Original Message-----
Dear BG:

If have found the best way to help someone with this
question is to
have them post the query the have now that shows the
results they want
but without the Rank column. It should sort the

results
so the #1
ranking row is at the top.

Please be advised that the results may show ties, and
will do so as
they would be in a horse race. If two horses finish
tied for first,
the next horse is in 3rd place, and there is no 2nd
place. OK?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 15:34:25 -0700, "BG"
wrote:

Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week and
sort
them by dollars. The query works but I don't know how
to
show ranking for each row in a seperate column. like
1st,
2nd, 3rd etc.
Can anyone please help.
Thanks

.


.


  #8  
Old September 12th, 2004, 06:40 PM
BG
external usenet poster
 
Posts: n/a
Default

autonumber is a good idea but how do you get it to start
from 1 everytime you clear the table?
I created a new table with an autonumber column for rank
and then deleted the records before each time I appended
the records but autonumber keeps on adding. I have to re-
run the query every week and second time I ran it started
from 26.
Is there a way to get it started from 1 everytime?

-----Original Message-----
I've done something similar before by outputting to a

table with an
autonumber field.

--
Ed

Remove the capital ST spam trap
when replying directly to me.


"BG" wrote in message
...
Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week and

sort
them by dollars. The query works but I don't know how

to
show ranking for each row in a seperate column. like

1st,
2nd, 3rd etc.
Can anyone please help.
Thanks



.

  #9  
Old September 13th, 2004, 12:02 AM
BG
external usenet poster
 
Posts: n/a
Default

It ran about 2 hrs and I got a similiar result. still
can't get the ranks from 1 to 25. I wish there was an
easier way to do.
I tried with insert query to a table with an autonumber
column but then when you do it more than once the second
time your rank starts with 26. I can't get it to start
with 1 every time.

so frustrating!


-----Original Message-----
Dear BG:

That would be because I missed the filter.

SELECT TOP 25 vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2 ,
(SELECT COUNT(*) + 1 FROM vw_sell_thru T1
INNER JOIN dbo_vw_MM_MATERIAL
ON T1.material = dbo_vw_MM_MATERIAL.MATERIAL
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
AND T1.last_wk_sls vw_sell_thru.last_wk_sls)

AS Rank
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru
INNER JOIN dbo_vw_MM_MATERIAL
ON vw_sell_thru.material =

dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT
ON dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
GROUP BY vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2
HAVING (vw_sell_thru.week_ending) = [week_ending_date]
ORDER BY vw_sell_thru.last_wk_sls DESC;

This is getting fairly complex. I hope I haven't had

too much trouble
fixing it up properly. It's not always easy for me.

So, what it was doing was to calculate the Rank using

every row in
vw_sell_thru, whereas it needs to use only those rows

where the joined
row of dbo_ww_MM_MATERIAL has Department 01. It was

apparently
finding a number of rows to count from that table that

you wanted to
exclude. Sorry, missed that, but it's obvious given the

problem you
had. Your description was just what I needed to know to

see what I
had missed.

Hope this is much better. And I hope this isn't getting

too complex
for Jet.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Fri, 10 Sep 2004 11:05:25 -0700, "BG"
wrote:

Hi Tom - I ran the query and the result didn't come as
expected. the first rank I get is 2 then 8,
45,47,60....and the last one is 468...
Any idea why it might have come that way?


-----Original Message-----
Dear MBGonul:

SELECT TOP 25 vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2 ,
(SELECT COUNT(*) + 1 FROM vw_sell_thru T1
WHERE T1.last_wk_sls vw_sell_thru.last_wk_sls)

AS Rank
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru
INNER JOIN dbo_vw_MM_MATERIAL
ON vw_sell_thru.material =

dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT
ON dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
GROUP BY vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2
HAVING (vw_sell_thru.week_ending) =

[week_ending_date]
ORDER BY vw_sell_thru.last_wk_sls DESC;

I have added the Rank column as the last one. Since

this is a SELECT
INTO the actual position of the Rank column will have

to
match the
Rank column in the destination table, which I couldn't

know.

Since you have ordered the results descending, I have

created the
ranking so the largest value will be ranked #1. This

is
an
assumption, and if it is not correct, change the in

my
additional
column to be .

Please let me know if this helped and if I can be of

any
other
assistance.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 16:33:34 -0700, "BG"

wrote:

Yes it's OK if there's a tie.

here's my query. Please let me know if this is what

you
asked me to post. Thanks for your help.
-------------------
SELECT TOP 25 vw_sell_thru.week_ending,
vw_sell_thru.account, vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru INNER JOIN dbo_vw_MM_MATERIAL ON
vw_sell_thru.material = dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT ON
dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE (((dbo_vw_MM_MATERIAL.DEPARTMENT)="01"))
GROUP BY vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
HAVING (((vw_sell_thru.week_ending)=

[week_ending_date]))
ORDER BY vw_sell_thru.last_wk_sls DESC;



-----Original Message-----
Dear BG:

If have found the best way to help someone with this
question is to
have them post the query the have now that shows the
results they want
but without the Rank column. It should sort the

results
so the #1
ranking row is at the top.

Please be advised that the results may show ties,

and
will do so as
they would be in a horse race. If two horses finish
tied for first,
the next horse is in 3rd place, and there is no 2nd
place. OK?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 15:34:25 -0700, "BG"
wrote:

Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week

and
sort
them by dollars. The query works but I don't know

how
to
show ranking for each row in a seperate column.

like
1st,
2nd, 3rd etc.
Can anyone please help.
Thanks

.


.


.

  #10  
Old September 13th, 2004, 02:05 PM
Tom Ellison
external usenet poster
 
Posts: n/a
Default

Dear BG:

If you'd like to send me a database with just this table, and if it
will zip to less than a megabyte, you could attach it to your email
and I'll look at it. There's enough code here it may be that I'm
having trouble getting it all right without there being any chance to
test it as I go.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Sun, 12 Sep 2004 16:02:17 -0700, "BG"
wrote:

It ran about 2 hrs and I got a similiar result. still
can't get the ranks from 1 to 25. I wish there was an
easier way to do.
I tried with insert query to a table with an autonumber
column but then when you do it more than once the second
time your rank starts with 26. I can't get it to start
with 1 every time.

so frustrating!


-----Original Message-----
Dear BG:

That would be because I missed the filter.

SELECT TOP 25 vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2 ,
(SELECT COUNT(*) + 1 FROM vw_sell_thru T1
INNER JOIN dbo_vw_MM_MATERIAL
ON T1.material = dbo_vw_MM_MATERIAL.MATERIAL
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
AND T1.last_wk_sls vw_sell_thru.last_wk_sls)

AS Rank
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru
INNER JOIN dbo_vw_MM_MATERIAL
ON vw_sell_thru.material =

dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT
ON dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
GROUP BY vw_sell_thru.week_ending,

vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2
HAVING (vw_sell_thru.week_ending) = [week_ending_date]
ORDER BY vw_sell_thru.last_wk_sls DESC;

This is getting fairly complex. I hope I haven't had

too much trouble
fixing it up properly. It's not always easy for me.

So, what it was doing was to calculate the Rank using

every row in
vw_sell_thru, whereas it needs to use only those rows

where the joined
row of dbo_ww_MM_MATERIAL has Department 01. It was

apparently
finding a number of rows to count from that table that

you wanted to
exclude. Sorry, missed that, but it's obvious given the

problem you
had. Your description was just what I needed to know to

see what I
had missed.

Hope this is much better. And I hope this isn't getting

too complex
for Jet.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Fri, 10 Sep 2004 11:05:25 -0700, "BG"
wrote:

Hi Tom - I ran the query and the result didn't come as
expected. the first rank I get is 2 then 8,
45,47,60....and the last one is 468...
Any idea why it might have come that way?


-----Original Message-----
Dear MBGonul:

SELECT TOP 25 vw_sell_thru.week_ending,
vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,
dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,
dbo_vw_MM_MATERIAL.COLOR_2 ,
(SELECT COUNT(*) + 1 FROM vw_sell_thru T1
WHERE T1.last_wk_sls vw_sell_thru.last_wk_sls)
AS Rank
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru
INNER JOIN dbo_vw_MM_MATERIAL
ON vw_sell_thru.material =
dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT
ON dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE dbo_vw_MM_MATERIAL.DEPARTMENT = "01"
GROUP BY vw_sell_thru.week_ending,
vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,
dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,
dbo_vw_MM_MATERIAL.COLOR_2
HAVING (vw_sell_thru.week_ending) =

[week_ending_date]
ORDER BY vw_sell_thru.last_wk_sls DESC;

I have added the Rank column as the last one. Since
this is a SELECT
INTO the actual position of the Rank column will have

to
match the
Rank column in the destination table, which I couldn't
know.

Since you have ordered the results descending, I have
created the
ranking so the largest value will be ranked #1. This

is
an
assumption, and if it is not correct, change the in

my
additional
column to be .

Please let me know if this helped and if I can be of

any
other
assistance.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 16:33:34 -0700, "BG"
wrote:

Yes it's OK if there's a tie.

here's my query. Please let me know if this is what

you
asked me to post. Thanks for your help.
-------------------
SELECT TOP 25 vw_sell_thru.week_ending,
vw_sell_thru.account, vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1,

dbo_vw_MM_MATERIAL.COLOR_2
INTO tbl_fw_top25_styles_lw_pairs
FROM (vw_sell_thru INNER JOIN dbo_vw_MM_MATERIAL ON
vw_sell_thru.material = dbo_vw_MM_MATERIAL.MATERIAL)
INNER JOIN dbo_vw_kd_BUSINESS_UNIT ON
dbo_vw_MM_MATERIAL.BUSINESS_UNIT_CODE =
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_CODE
WHERE (((dbo_vw_MM_MATERIAL.DEPARTMENT)="01"))
GROUP BY vw_sell_thru.week_ending,
vw_sell_thru.account,
vw_sell_thru.last_wk_sls,
dbo_vw_kd_BUSINESS_UNIT.BUSINESS_UNIT_DESC,
vw_sell_thru.material,

dbo_vw_MM_MATERIAL.DESCRIPTION,
dbo_vw_MM_MATERIAL.COLOR_1, dbo_vw_MM_MATERIAL.COLOR_2
HAVING (((vw_sell_thru.week_ending)=

[week_ending_date]))
ORDER BY vw_sell_thru.last_wk_sls DESC;



-----Original Message-----
Dear BG:

If have found the best way to help someone with this
question is to
have them post the query the have now that shows the
results they want
but without the Rank column. It should sort the
results
so the #1
ranking row is at the top.

Please be advised that the results may show ties,

and
will do so as
they would be in a horse race. If two horses finish
tied for first,
the next horse is in 3rd place, and there is no 2nd
place. OK?

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Thu, 9 Sep 2004 15:34:25 -0700, "BG"
wrote:

Hi - I appreciate any help you can give me on this.
I am trying to show top 25 styles sold in a week

and
sort
them by dollars. The query works but I don't know

how
to
show ranking for each row in a seperate column.

like
1st,
2nd, 3rd etc.
Can anyone please help.
Thanks

.


.


.


 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I identify different numbers to a table of numbers Erich Niemand Worksheet Functions 1 September 9th, 2004 04:25 AM
Can't see old phone numbers rleblanc Using Forms 4 August 28th, 2004 05:12 PM
Repost: Calculation problem. Someone help! Victor Running & Setting Up Queries 13 August 6th, 2004 05:21 PM
Formatting Numbers Allison Worksheet Functions 3 March 31st, 2004 09:55 PM
How to get excel to find the numbers of times 2 numbers appear Gary Hunt Worksheet Functions 2 March 21st, 2004 10:32 PM


All times are GMT +1. The time now is 12:33 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.