SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2003
    0 Post(s)
    0 Thread(s)

    Distributing results evenly

    I have 10 different stores, each of which has a number of products.

    Product(product_id, store_id, name, .....)

    A simple select returns the list of products in order of store_id (as this is they way they are inserted). However what I want is a list of products that are distributed evenly across each store.

    At the moment the result set looks like:
    Store 1 - Product 1
    Store 1 - product 2
    Store 2 - product 1
    Store 2 - product 2
    Store 2 - product 3
    Store 3 - product 1

    But I want something like:
    Store 3 - Product 1
    Store 1 - Product 2
    Store 2 - Product 3
    Store 1 - Product 1
    Store 3 - Product 2

    It by no means has to be perfect, I just want some sort of even spread of products from different stores, so those from the same store are not clumped together.

    I have no other column I can order by to give the desired effect and the only other solution I can think of is asigning random numbers to records and using this.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Philadephia, PA
    1 Post(s)
    0 Thread(s)
    If you want random ordering then ORDER BY RAND()

    Randomness will produce clumps all on its own, though. An even distribution is statistically improbable in a random sequence.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts