Copy codeThe Code is as follows:
Select *
FROM table1
Where (id in (, 2 ))
Copy codeThe Code is as follows:
Select *
FROM table1
Where (id in (, 2) if all the conditions after In are numbers, the MSSQL sorting should be
Copy codeThe Code is as follows:
Select *
FROM table1
Where (id in (, 2 ))
OrDER by charindex (',' + CONVERT (nvarchar, ID) + ',' + CONVERT (nvarchar, Replace ('3, 5, 1, 4, 2 ','', '') + ',')
Copy codeThe Code is as follows:
Select *
FROM table1
Where (id in (, 2 ))
OrDER by charindex (',' + CONVERT (nvarchar, ID) + ',' + CONVERT (nvarchar, Replace ('3, 5, 1, 4, 2 ','', '') + ',') improve the method. Instead of processing spaces, use spaces to judge. it can be used to determine a few character conditions with spaces.
Copy codeThe Code is as follows:
Select *
FROM table1
Where (id in (, 2 ))
OrDER by patindex ('%' + CONVERT (nvarchar (4000), ID) + '%', ''+ CONVERT (nvarchar (4000), Replace ('3, 5, 1, 4, 2 ',') + '')
Copy codeThe Code is as follows:
Select *
FROM table1
Where (id in (, 2 ))
OrDER by patindex ('%' + CONVERT (nvarchar (4000), ID) + '%', ''+ CONVERT (nvarchar (4000), Replace ('3, 5, 1, 4, 2 ',') + '')
In fact, it is better to query and sort conditional strings after processing them out of SQL.
For MYSQL sorting, it may be changed to (not familiar with MYSQL ):
Copy codeThe Code is as follows:
Select *
FROM table1
Where (id in (, 2 ))
OrDER BY FIND_IN_SET (ID, '3, 5, 1, 4, 2 ')