List:General Discussion« Previous MessageNext Message »
From:Sasha Pachev Date:July 9 1999 4:44am
Subject:Re: Really *REALLY* weird ORDER BY
View as plain text  
Para-dox wrote:
> 
> (please send directly to me)
> 
> I have a bunch of records in a table that need to be sorted by a field
> called PRICE, only they have to be sorted in a special "bell-shaped way."
> Like this set:
> 
> 0.10
> 0.35
> 0.25
> 0.55
> 0.79
> 0.12
> 
> would be sorted like this:
> 
> 0.10
> 0.25
> 0.55
> 0.79
> 0.35
> 0.12
> 
> The most expensive ones are in the middle, while the least expensive are on
> the outside, this can be accomplished by grabbing them lowest to highest and
> alternating inserting them from the top and bottom. How can I do this in an
> SQL ORDER BY?
> 
> Thanks, Dave (paradox@stripped)
> 

That is an interesting problem. I do not see any simple straight SQL
solution. Here is what I would do:

- If the number of records is relatively small, just sort it in the
application
- If there are a lot of records coming back from the query, and sorting
in the application is not acceptable performance-wise, patch ( hack)
mysql server to add new syntax ORDER BY <col_name> BELL - this will make
BELL a keyword, but heck, who cares, it's your own server now and
implement your bells sort - should not be to hard, just look at how it
handles ORDER BY ... ASC and ORDER BY .. DESC

-- 
Sasha Pachev
http://www.sashanet.com
Thread
Really *REALLY* weird ORDER BYPara-dox9 Jul
  • Re: Really *REALLY* weird ORDER BYSasha Pachev9 Jul
    • Re: Really *REALLY* weird ORDER BYBob Worthy9 Jul
      • Re: Really *REALLY* weird ORDER BYMartin Ramsch27 Jul