dbTalk Databases Forums  

Ranking by group

comp.databases.ms-access comp.databases.ms-access


Discuss Ranking by group in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Astley Le Jasper
 
Posts: n/a

Default Ranking by group - 04-13-2009 , 10:36 AM






I adopted a ranking approach which I found here (http://
allenbrowne.com/ranking.html)

However, I am doing rankings by product and by working week. The code
is:

A) Core query (xx_test2)

SELECT weeks, product_name, website, Min(price) AS minprice
FROM product_history
GROUP BY weeks, product_name, website;

B) Sub query

SELECT weeks, product_name, website, minprice,
(SELECT count(website) AS howmany
FROM xx_test2 AS dupe
WHERE ((dupe.minprice<xx_test2.minprice)
AND (dupe.weeks=xx_test2.weeks)
AND (dupe.product_name = xx_test2.product_name)))+1 AS rank
FROM xx_test2;

The trouble is that the core table has currently 80k records and
growing, and the report is already very very slow (half an hour and
then i decided to quit it).

Does anyone have any suggestions to improve performance? Would it make
any difference looping the query to do an append and changing the
product and week parameters? I can't imagine it would. The other
alternative is that I keep a permanent rank table and append the
weekly results each week. Or is this query completely wrong!

Ta

ALJ

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Ranking by group - 04-13-2009 , 12:14 PM






Astley Le Jasper wrote:
Quote:
I adopted a ranking approach which I found here (http://
allenbrowne.com/ranking.html)

However, I am doing rankings by product and by working week. The code
is:

A) Core query (xx_test2)

SELECT weeks, product_name, website, Min(price) AS minprice
FROM product_history
GROUP BY weeks, product_name, website;

B) Sub query

SELECT weeks, product_name, website, minprice,
(SELECT count(website) AS howmany
FROM xx_test2 AS dupe
WHERE ((dupe.minprice<xx_test2.minprice)
AND (dupe.weeks=xx_test2.weeks)
AND (dupe.product_name = xx_test2.product_name)))+1 AS rank
FROM xx_test2;

The trouble is that the core table has currently 80k records and
growing, and the report is already very very slow (half an hour and
then i decided to quit it).

Does anyone have any suggestions to improve performance? Would it make
any difference looping the query to do an append and changing the
product and week parameters? I can't imagine it would. The other
alternative is that I keep a permanent rank table and append the
weekly results each week. Or is this query completely wrong!

Ta

ALJ
You have
WHERE ((dupe.minprice<xx_test2.minprice)
Would it ever be less than minprice of test2?

Are you printing a report? 80K records is a lot to print.

In the core query you group on the website (as well as product and
week). Do you really need to group on the website as well?

Instead of ranking, couldn't you sort on
weeks, product_name, price, website
and achieve the same thing? When printing a report, use a running sum
over the group to show the ranking?


Reply With Quote
  #3  
Old   
Astley Le Jasper
 
Posts: n/a

Default Re: Ranking by group - 04-13-2009 , 02:40 PM



On 13 Apr, 19:14, Salad <o... (AT) vinegar (DOT) com> wrote:
Quote:
Astley Le Jasper wrote:
I adopted a ranking approach which I found here (http://
allenbrowne.com/ranking.html)

However, I am doing rankings by product and by working week. The code
is:

A) Core query (xx_test2)

SELECT weeks, product_name, website, Min(price) AS minprice
FROM product_history
GROUP BY weeks, product_name, website;

B) Sub query

SELECT weeks, product_name, website, minprice,
* (SELECT count(website) AS howmany
* FROM xx_test2 AS dupe
* WHERE ((dupe.minprice<xx_test2.minprice)
* AND (dupe.weeks=xx_test2.weeks)
* AND (dupe.product_name = xx_test2.product_name)))+1 AS rank
FROM xx_test2;

The trouble is that the core table has currently 80k records and
growing, and the report is already very very slow (half an hour and
then i decided to quit it).

Does anyone have any suggestions to improve performance? Would it make
any difference looping the query to do an append and changing the
product and week parameters? I can't imagine it would. The other
alternative is that I keep a permanent rank table and append the
weekly results each week. Or is this query completely wrong!

Ta

ALJ

You have
* * * * WHERE ((dupe.minprice<xx_test2.minprice)
Would it ever be less than minprice of test2?

Are you printing a report? *80K records is a lot to print.

In the core query you group on the website (as well as product and
week). *Do you really need to group on the website as well?

Instead of ranking, couldn't you sort on
* * * * weeks, product_name, price, website
and achieve the same thing? *When printing a report, use a running sum
over the group to show the ranking?
Hi Salad,

- The 'where' element is part of the ranking, counting how many
records are less than the current record.
- No, I'm not printing a report. I'm going to use it as the basis of
further analysis, charting, trends etc.
- No, unfortunately just ordering isn't going to cut it for the sort
of analysis we want to do. We're trying to check which are the current
and historic cheapest websites.

ALJ


Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: Ranking by group - 04-13-2009 , 03:17 PM



Astley Le Jasper wrote:

Quote:
On 13 Apr, 19:14, Salad <o... (AT) vinegar (DOT) com> wrote:

Astley Le Jasper wrote:

I adopted a ranking approach which I found here (http://
allenbrowne.com/ranking.html)

However, I am doing rankings by product and by working week. The code
is:

A) Core query (xx_test2)

SELECT weeks, product_name, website, Min(price) AS minprice
FROM product_history
GROUP BY weeks, product_name, website;

B) Sub query

SELECT weeks, product_name, website, minprice,
(SELECT count(website) AS howmany
FROM xx_test2 AS dupe
WHERE ((dupe.minprice<xx_test2.minprice)
AND (dupe.weeks=xx_test2.weeks)
AND (dupe.product_name = xx_test2.product_name)))+1 AS rank
FROM xx_test2;

The trouble is that the core table has currently 80k records and
growing, and the report is already very very slow (half an hour and
then i decided to quit it).

Does anyone have any suggestions to improve performance? Would it make
any difference looping the query to do an append and changing the
product and week parameters? I can't imagine it would. The other
alternative is that I keep a permanent rank table and append the
weekly results each week. Or is this query completely wrong!

Ta

ALJ

You have
WHERE ((dupe.minprice<xx_test2.minprice)
Would it ever be less than minprice of test2?

Are you printing a report? 80K records is a lot to print.

In the core query you group on the website (as well as product and
week). Do you really need to group on the website as well?

Instead of ranking, couldn't you sort on
weeks, product_name, price, website
and achieve the same thing? When printing a report, use a running sum
over the group to show the ranking?


Hi Salad,

- The 'where' element is part of the ranking, counting how many
records are less than the current record.
Having dupe minimum < the test minimum doesn't seem right for some odd
reason.

I see absolutely no reason to group by website in your core query.

Quote:
- No, I'm not printing a report. I'm going to use it as the basis of
further analysis, charting, trends etc.
Are you stuffing the ranking to a field?

Do you have to recompute the ranking for the entire database each time
you want to do some analysis?

Quote:
- No, unfortunately just ordering isn't going to cut it for the sort
of analysis we want to do. We're trying to check which are the current
and historic cheapest websites.
for a particular weeks period and product.

Well, I've seen in the past something like
dcount("*","table","ID <= " & [ID]) + 1
in the past.

What happens if you have a query1 that gets the weeks, product, and min
price.

The create query2. It links query1 to the table on weeks and product
and counts the number of price-min records less than the records price
-min. I wouldn't know how you'd rank ties as you seem to have no id in
your table.

Quote:
ALJ

Reply With Quote
  #5  
Old   
Astley Le Jasper
 
Posts: n/a

Default Re: Ranking by group - 04-14-2009 , 07:59 AM



Quote:
Having dupe minimum < the test minimum doesn't seem right for some odd
reason.
I know ... but it works.

Quote:
I see absolutely no reason to group by website in your core query.
True but I need the website and the complains if it isn't summarised
in some way, and I also don't think that the first query is very slow.

Quote:
Are you stuffing the ranking to a field?
Yes

Quote:
Do you have to recompute the ranking for the entire database each time you want to do some analysis?
I was going to use this to create a temp table when the database
opens. It would pick up any changes to the history if they were made.
However, I'm thinking that if I can't do this faster I'm giong to have
to do incremental appends when new data comes in. Still, even getting
the base ranked table is taking ages.

Quote:
What happens if you have a query1 that gets the weeks, product, and min price.
That's what's it's doing at the moment with the core query

Quote:
The create query2. It links query1 to the table on weeks and product and counts the number of price-min records less than the records price-min. I wouldn't know how you'd rank ties as you seem to have no id in your table.
The expression that generates 'rank' bundles those records that are
related (by week and product) together so only those are counted.


Gaaaahh! You would have thought this was something that would be built-
in!


Reply With Quote
  #6  
Old   
Salad
 
Posts: n/a

Default Re: Ranking by group - 04-14-2009 , 08:41 AM



Astley Le Jasper wrote:

Quote:
Are you stuffing the ranking to a field?

Yes
Maybe sort the file in its order and then use AbsolutePosition to get
the record number. Don't know if AbsolutePosition is available in a
query but I'd think scanning 80K records would be quick.
Set rst = ...
with rst
Do while not eof
.Edit
...
.Update
Loop
end with

Quote:
Do you have to recompute the ranking for the entire database each time you want to do some analysis?

I was going to use this to create a temp table when the database
opens. It would pick up any changes to the history if they were made.
However, I'm thinking that if I can't do this faster I'm giong to have
to do incremental appends when new data comes in. Still, even getting
the base ranked table is taking ages.


What happens if you have a query1 that gets the weeks, product, and min price.

That's what's it's doing at the moment with the core query
Notice I didn't have website.

Quote:
The create query2. It links query1 to the table on weeks and product and counts the number of price-min records less than the records price-min. I wouldn't know how you'd rank ties as you seem to have no id in your table.

The expression that generates 'rank' bundles those records that are
related (by week and product) together so only those are counted.

But the ranking is on websites. That's not required in the first query.

Gaaaahh! You would have thought this was something that would be built-
in!
Wish it was.


Reply With Quote
  #7  
Old   
Astley Le Jasper
 
Posts: n/a

Default Re: Ranking by group - 04-16-2009 , 03:01 AM



On Apr 14, 3:41*pm, Salad <o... (AT) vinegar (DOT) com> wrote:
Quote:
Astley Le Jasper wrote:
Are you stuffing the ranking to a field?

Yes

Maybe sort the file in its order and then use AbsolutePosition to get
the record number. *Don't know if AbsolutePosition is available in a
query but I'd think scanning 80K records would be quick.
* * * * Set rst = ...
* * * * with rst
* * * * * * * * Do while not eof
* * * * * * * * .Edit
* * * * * * * * ...
* * * * * * * * .Update
* * * * * * * * Loop
* * * * end with

Do you have to recompute the ranking for the entire database each time you want to do some analysis?

I was going to use this to create a temp table when the database
opens. It would pick up any changes to the history if they were made.
However, I'm thinking that if I can't do this faster I'm giong to have
to do incremental appends when new data comes in. Still, even getting
the base ranked table is taking ages.

What happens if you have a query1 that gets the weeks, product, andmin price.

That's what's it's doing at the moment with the core query

Notice I didn't have website.

The create query2. *It links query1 to the table on weeks and product and counts the number of price-min records less than the records price-min. *I wouldn't know how you'd rank ties as you seem to have no id in your table.

The expression that generates 'rank' bundles those records that are
related (by week and product) together so only those are counted.

But the ranking is on websites. *That's not required in the first query..



Gaaaahh! You would have thought this was something that would be built-
in!

Wish it was.
Thanks salad. I'll have a look at that loop.

ALJ


Reply With Quote
  #8  
Old   
Salad
 
Posts: n/a

Default Re: Ranking by group - 04-16-2009 , 01:06 PM



Astley Le Jasper wrote:

Quote:
On Apr 14, 3:41 pm, Salad <o... (AT) vinegar (DOT) com> wrote:

Astley Le Jasper wrote:

Are you stuffing the ranking to a field?

Yes

Maybe sort the file in its order and then use AbsolutePosition to get
the record number. Don't know if AbsolutePosition is available in a
query but I'd think scanning 80K records would be quick.
Set rst = ...
with rst
Do while not eof
.Edit
...
.Update
Loop
end with


Do you have to recompute the ranking for the entire database each time you want to do some analysis?

I was going to use this to create a temp table when the database
opens. It would pick up any changes to the history if they were made.
However, I'm thinking that if I can't do this faster I'm giong to have
to do incremental appends when new data comes in. Still, even getting
the base ranked table is taking ages.

What happens if you have a query1 that gets the weeks, product, and min price.

That's what's it's doing at the moment with the core query

Notice I didn't have website.


The create query2. It links query1 to the table on weeks and product and counts the number of price-min records less than the records price-min. I wouldn't know how you'd rank ties as you seem to have no id in your table.

The expression that generates 'rank' bundles those records that are
related (by week and product) together so only those are counted.

But the ranking is on websites. That's not required in the first query.




Gaaaahh! You would have thought this was something that would be built-
in!

Wish it was.


Thanks salad. I'll have a look at that loop.

ALJ
If you have 80K records to rank, I'll assume it will take some time to
calc...no matter what you do. It might be fastest to order the table
first then scan thru the records. Your break would be on week/product
and rank the website based on the price.


Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.