- 论坛徽章:
- 0
|
mysql> create table tt (id varchar(5),ord decimal(10,0),title varchar(10)) ;
Query OK, 0 rows affected (1.09 sec)
mysql> insert into tt values ('1',54,'abc') ;
Query OK, 1 row affected (0.03 sec)
mysql> insert into tt values ('2',35,'ff') ;
Query OK, 1 row affected (0.01 sec)
mysql> insert into tt values ('3',15,'ee') ;
Query OK, 1 row affected (0.01 sec)
mysql> insert into tt values ('4',20,'eedd') ;
Query OK, 1 row affected (0.00 sec)
mysql>
mysql>
mysql>
mysql> select * From tt order by id ;
+------+------+-------+
| id | ord | title |
+------+------+-------+
| 1 | 54 | abc |
| 2 | 35 | ff |
| 3 | 15 | ee |
| 4 | 20 | eedd |
+------+------+-------+
4 rows in set (0.04 sec)
select (case when id='1' then '2' when id='2' then '1' else id end ) as id ,ord,title From tt order by (case when id='1' then '2' when id='2' then '1' else id end ) ;
+------+------+-------+
| id | ord | title |
+------+------+-------+
| 1 | 35 | ff |
| 2 | 54 | abc |
| 3 | 15 | ee |
| 4 | 20 | eedd |
+------+------+-------+
4 rows in set (0.00 sec)
mysql>
mysql>
mysql> select (case when xx.id='1' then '2' when xx.id='2' then '1' else xx.id end ) as id ,xx.ord,t.title
-> From
-> tt xx, (select (case when id='1' then '2' when id='2' then '1' else id end ) as id , ord, title From tt ) t
-> where xx.id=t.id order by (case when xx.id='1' then '2' when xx.id='2' then '1' else xx.id end );
+------+------+-------+
| id | ord | title |
+------+------+-------+
| 1 | 35 | abc |
| 2 | 54 | ff |
| 3 | 15 | ee |
| 4 | 20 | eedd |
+------+------+-------+
4 rows in set (0.00 sec)
后面那个 SQL 就能完全满足你的要求。。你试试 ?
不过你的要求有些奇怪.。。 呵呵。 |
|