I have a column with identifiers that I want to sort. It has identifier values from 1 to 3. However, instead of just using ASC DESC, I want to do a normal sort on 2, 3, 1. How can I do this?
I think the easiest way is to do it like this:
SELECT * FROM `mytable` ORDER BY FIND_IN_SET(id, '2,3,1')
You can add a virtual column with values
MOD(ID, 3)
and request your ascending request. For instance:
SELECT somecolumn, MOD(ID, 3) AS ordered_id FROM my_table ORDER BY ordered_id
Unverified:
SELECT ..., IF(ID=2, 1, IF(ID=3, 2, 3)) AS orderByValue FROM ... ORDER BY orderByValue
It uses the IF function to convert identifier values:
ID orderByValue 2 1 3 2 else 3
Source: https://habr.com/ru/post/1744635/More articles:View iPad Simulator - ios-simulatorPython: заменить URL-адреса с названиями имен из строки - pythonOracle Schema Name - c #How to have excel addin read rows from a worksheet until there is more data? - c #OpenGL game written in C with Cocoa interface, I want to connect to Windows - cCalculate differences between rows when grouping with SQL - sqlError using --static option with macrubyc - ruby | fooobar.commanaging individual contacts on a serial port - c ++https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1744639/whats-the-correct-way-to-instantiate-an-irepository-class-from-the-controller&usg=ALkJrhhTYhxhZ4A3BZP77dj8qrWVpIBktgRails: how can I check this code that I entered in the lib / directory? - ruby | fooobar.comAll Articles