Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
-none-

-none-

2007-10-12       - By Adam Randall

 Back
Here's my full test solution:

use test;

drop table if exists releases;
create temporary table releases
(
  releaseid int(10) unsigned not null auto_increment primary key,
  name varchar(255)
)engine=myisam;

insert into releases ( name ) values
( 'Unspecified' ),
( 'Next Patch' ),
( 'LOCset' ),
( 'Abashiri' ),
( '4.6.0 (Folsom)' ),
( '4.5.9' ),
( '4.5.6' ),
( '4.5.5 (Purdy)' ),
( '4.5.5' ),
( '4.5.4' ),
( '4.5.3' ),
( '4.5.2' ),
( '4.5.10' ),
( '4.5.1 Deferred' ),
( '4.5.1 (Leavenworth)' ),
( '4.2.7.4' ),
( '4.2.7.3' ),
( '4.2.7.2' ),
( '4.2.7.1' ),
( '4.2.7.0' );

select
  releaseid,
  name
from
  releases
order by
  case name
    when 'Unspecified' then 0
    when 'Next Patch' then 1
    when 'LOCset' then 2
    else 10
  end,
  if(
    locate( ' ', name ) > 0 and locate( '.', name ) > 0,
    inet_aton( substr( name, 1, locate( ' ', name ) - 1 ) ),
    if(
      locate( '.', name ) > 0,
      inet_aton( name ),
      4294967295 ) ) desc,
  if(
    locate( ' ', name ) > 0 and locate( '.', name ) > 0,
    replace( replace( substr( name, locate( ' ', name ) + 1 ), '(',  
'' ), ')', '' ),
    if(
      locate( '.', name ) = 0,
      name,
      null ) );

This is the end result after talking to Daevid and finding out what  
the ultimate goal was. I think it's kind of clever myself :)

Yes, there's no possibility of indexing here, but it gets the job done.

Adam.

On Oct 12, 2007, at 12:39 PM, Daevid Vincent wrote:

>
> I'm trying to get some 'release/version numbers' to sort properly.
>
> mysql> SELECT ReleaseID, Name FROM releases ORDER BY Name DESC;
> +-- ---- ---+-- ---- ---- ---- ---+
> | ReleaseID | Name                |
> +-- ---- ---+-- ---- ---- ---- ---+
> |        18 | Unspecified         |
> |        20 | Next Patch          |
> |        58 | LOCset              |
> |        74 | Abashiri            |
> |        54 | 4.6.0 (Folsom)      |
>              <-- 4.5.10 should be here
> |        99 | 4.5.9               |
> |        98 | 4.5.6               |
> |        93 | 4.5.5 (Purdy)       |
> |        97 | 4.5.4               |
> |        96 | 4.5.3               |
> |        94 | 4.5.2               |
> |       100 | 4.5.10              |   <-- should be ^ there
> |        91 | 4.5.1 Deferred      |
> |        78 | 4.5.1 (Leavenworth) |
> |        95 | 4.2.7.4             |
> |        92 | 4.2.7.3             |
> |        90 | 4.2.7.2             |
> |        87 | 4.2.7.1             |
> |        88 | 4.2.7.0             |
>
> I like this order, especially with the top four,
> except for that 4.5.10 should be higher up,
> just under 4.6.0, not under 4.5.2 as it is now.
>
> So I tried the " + 0 " trick which makes things even worse
> (notice the 4.2.6.1 and 4.2.6.0 -- yipes!):
>
> mysql> SELECT ReleaseID, Name FROM releases ORDER BY Name + 0 DESC;
> +-- ---- ---+-- ---- ---- ---- ---+
> | ReleaseID | Name                |
> +-- ---- ---+-- ---- ---- ---- ---+
>             ....(18,20,58,74) are moved
> :(
> |        54 | 4.6.0 (Folsom)      |
> |        78 | 4.5.1 (Leavenworth) |
> |       100 | 4.5.10              |
> |        91 | 4.5.1 Deferred      |
> |        93 | 4.5.5 (Purdy)       |
> |        94 | 4.5.2               |
> |        96 | 4.5.3               |
> |        97 | 4.5.4               |
> |        98 | 4.5.6               |
> |        99 | 4.5.9               |
> |        82 | 4.2.6.1             |  <<  ?
> |        76 | 4.2.2               |
> |        75 | 4.2.4               |
> |        72 | 4.2.1               |
> |        73 | 4.2.3               |
> |        67 | 4.2.6.0             |  <<  ?
>
>
> I'm pretty sure this is going to involve some sort of splitting the  
> version
> from the release codeword via some string functions, and then  
> operating on
> that part.
>
>
> D.Vin
> http://daevid.com
> ---
> eval() is my favorite templating engine.
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=randalla@(protected)
>


--
Adam Randall
randalla@(protected)




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=mysql@(protected)