Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

order 1 3 2
Hello
I can't find how to order my resultset that way :
ID
---
1
3
2

any idea ?

Thanx !

Flo





Report this thread to moderator Post Follow-up to this message
Old Post
Florian
11-19-04 08:57 PM


Re: order 1 3 2
What database you use?

In Oracle 8i (and probably newer versions too) you could do:

SELECT id
FROM my_table
ORDER BY DECODE( id, 1, 1, 3, 2, 2, 3, id )


In MS SQL Server 2000 you could do:

SELECT id
FROM my_table
ORDER BY CASE id WHEN 1 THEN 1 WHEN 3 THEN 2 WHEN 2 THEN 3 ELSE id END


Hilarion



Report this thread to moderator Post Follow-up to this message
Old Post
Hilarion
11-19-04 08:57 PM


Re: order 1 3 2
> ID
> ---
> 1
> 3
> 2

ORDER BY ID*(9-2*ID)

--
Vincent
More unreadable code ;)



Report this thread to moderator Post Follow-up to this message
Old Post
Vincent Lascaux
11-23-04 01:56 AM


Re: order 1 3 2
>> ID 
>
> ORDER BY ID*(9-2*ID)

Nice. How did you get to this idea? I suppose there's
some math behind it (computing formula based on three
coordinates, but why those three points?).

Hilarion



Report this thread to moderator Post Follow-up to this message
Old Post
Hilarion
11-23-04 01:56 PM


Re: order 1 3 2
>> ORDER BY ID*(9-2*ID)
>
> Nice. How did you get to this idea? I suppose there's
> some math behind it (computing formula based on three
> coordinates, but why those three points?).

f(x) = -(x-a)² takes it maximum in a and is symetrical / a.
You want f(1) < f(3) < f(2). a must be closer to 2 so that f(2) is the
highest value and one the side of 3 so that f(3) > f(1).
Any a between 2 and 2.5 exclusive is ok (smaller than 2 and f(1) > f(3) and
larger than 2.5 and f(3) > f(2)). I chose 2.25

-(x-2.25)² = -x² + 4.5x - 2.25². You can get rid of the constant since the
only interesting thing is the ordering (not the value of f) and I multiplied
everything by 2 to have integer values. -2x²+9x = x(9-2x)

--
Vincent



Report this thread to moderator Post Follow-up to this message
Old Post
Vincent Lascaux
11-23-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:22 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.