By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

changing values based on top 3 highest numbers in a list

P: 1
I have a module which lists the top 3 products on my website by views that week. Every week it resets to 0. I would like for the top product in this list to be discounted by 15 percent, the second by 10 percent and the third by 5 percent. The discounts are managed by a discount_id column. I can easily accomplish this but the problem is that the list is constantly changing and I need the old discount_id to be put back in when the product drops out of the top 3 list. So what I need in simple terms is:

if product is in top 3 list, copy discount_id to old_discount_id and then change discount_id. If product is no longer in top 3 list, copy old_discount_id over to discount_id. I also need it to distinguish between the different discount rate for each of the top 3 products. Is there a better way of doing this? Thanks for your time.
Oct 8 '11 #1
Share this Question
Share on Google+
1 Reply


YarrOfDoom
Expert 100+
P: 1,247
It might be more easy to have a second table with 3 records: the new discount_id's and their associated product id's.
Then use a LEFT JOIN (or a RIGHT JOIN, depending on your query) when you lookup the products table and need the discount_id column.
Oct 10 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.