Home > database >  Mysql Id range queries
Mysql Id range queries

Time:10-09

How to found out the data according to my Id in order to find out?

Below 12,11,14 phase to the query result Id Id is 12,11,14

CodePudding user response:

You can refer to this practice:

 
SELECT *,
The CASE id
WHEN 2 THEN 1
WHEN 1 THEN 2
The WHEN 4 THEN 3
END 'my_sort'
The FROM ` sales `
,1,4 WHERE id IN (2)
The ORDER BY my_sort ASC


Need to remind is, forced ranking index of SQL is not to walk so, regardless of the amount of a large number of small, not very recommended to do so; Still had better think about it, by other ways;

CodePudding user response:

Select * from your_table t where id in (12,11,14) order by filed (t.i d, 12,11,14)
Understand the fix field function

CodePudding user response:

The three values, wrote a temporary table, also a solution,
  • Related