changing values based on top 3 highest numbers in a list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ant Old
    New Member
    • Oct 2011
    • 1

    changing values based on top 3 highest numbers in a list

    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.
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    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.

    Comment

    Working...