表结构如下:
mysql> select * from test;
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | test4 |
| 5 | test5 |
+----+-------+
执行以下SQL:
mysql> select * from test where id in(3,1,5);
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 3 | test3 |
| 5 | test5 |
+----+-------+
3 rows in set (0.00 sec)
这个select在mysql中得结果会自动按照id升序排列,
但是我想执行"select * from test where id in(3,1,5);"的结果按照in中得条件排序,即:3,1,5,想得到的结果如下:
id name
3 test3
1 test1
5 test5
select id, name from table where 'daodao' IN (list);
IN (list); 如果list是常量,则可以直接用IN,大家怎么看?
mysql> select * from test;
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | test4 |
| 5 | test5 |
+----+-------+
执行以下SQL:
mysql> select * from test where id in(3,1,5);
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 3 | test3 |
| 5 | test5 |
+----+-------+
3 rows in set (0.00 sec)
这个select在mysql中得结果会自动按照id升序排列,
但是我想执行"select * from test where id in(3,1,5);"的结果按照in中得条件排序,即:3,1,5,想得到的结果如下:
id name
3 test3
1 test1
5 test5
mysql> select * from Tbl_FQQ_FScoreCount where id in(3,1,5) order by find_in_set(id,'3,1,5');
+----+-----------+-------------+
| ID | FQQ | FScoreCount |
+----+-----------+-------------+
| 3 | 715113297 | 40 |
| 1 | 78540474 | 37 |
| 5 | 1735548 | 0 |
+----+-----------+-------------+
+----+-----------+-------------+
| ID | FQQ | FScoreCount |
+----+-----------+-------------+
| 3 | 715113297 | 40 |
| 1 | 78540474 | 37 |
| 5 | 1735548 | 0 |
+----+-----------+-------------+
select id, name from table where 'daodao' IN (list);
IN (list); 如果list是常量,则可以直接用IN,大家怎么看?
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/3401/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表