0

関数の順序で指定したパラメーター値の順序で SQL クエリの結果セットが必要です。

mysql> select * from state where state_name in ("UP","AP","Orissa","MP");

+------------+
| state_name |
+------------+
| AP         |
| MP         |
| UP         |
| Orissa     |
+------------+

4 行セット (0.00 秒)

余分な挿入や作成を使用せずに役立つ解決策を提案してください。

4

3 に答える 3

2
select * from state where state_name in ("UP","AP","Orissa","MP")    
order by FIELD(state_name ,"UP","AP","Orissa","MP")
于 2014-12-06T13:30:04.663 に答える
0

古い学校:

SELECT
  State.*
FROM State
JOIN (SELECT 'UP' sn, '1' pos UNION ALL
      SELECT 'AP', '2' UNION ALL
      SELECT 'Orissa', '3' UNION ALL
      SELECT 'MP', '4') SortOrder
ON State.state_name = SortOrder.sn
ORDER BY SortOrder.pos;

SQL フィドル

于 2014-12-06T14:29:59.730 に答える
0

ANSI sql CASE を使用

select * from state where state_name in ("UP","AP","Orissa","MP")
order by case state_name 
         when "UP" then 1 
         when "AP" then 2 
         when "Orissa" then 3 
         when "MP" then 4 
         else 5 end;
于 2014-12-06T13:32:01.803 に答える