MySQL sort order by array value

故事扮演 提交于 2019-11-28 04:56:46
hari jee

You want to get a list of items with the ids 5, 2, 1, 3 and output them in the same order. However, just running a select query will return the items in the order 1, 2, 3, 5.

To order the results correctly you need to build a list of ORDER BY items describing the weights of the ids. This will look like

ORDER BY id = 5 DESC, id = 2 DESC, id = 1 DESC, id = 3 DESC

Go to this link to get the details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!