Mysql select in 按id排序?qū)崿F(xiàn)方法
mysql> select * from test;
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | test4 |
| 5 | test5 |
+----+-------+
執(zhí)行以下SQL:
mysql> select * from test where id in(3,1,5);
+----+-------+
| id | name |
+----+-------+
| 1 | test1 |
| 3 | test3 |
| 5 | test5 |
+----+-------+
3 rows in set (0.00 sec)
這個(gè)select在mysql中得結(jié)果會(huì)自動(dòng)按照id升序排列,
但是我想執(zhí)行"select * from test where id in(3,1,5);"的結(jié)果按照in中得條件排序,即:3,1,5,
想得到的結(jié)果如下:
id name
3 test3
1 test1
5 test5
請(qǐng)問(wèn)在這樣的SQL在Mysql中怎么寫?
網(wǎng)上查到sqlserver中可以用order by charindex解決,但是沒(méi)看到Mysql怎么解決??請(qǐng)高手幫忙,謝
謝!
select * from a order by substring_index('3,1,2',id,1);
試下這個(gè)good,ls正解。
order by find_in_set(id,'3,1,5')
謝謝,經(jīng)測(cè)試order by substring_index和order by find_in_set都可以
- Mysql中的排序規(guī)則utf8_unicode_ci、utf8_general_ci的區(qū)別總結(jié)
- 讓MySQL支持中文排序的實(shí)現(xiàn)方法
- mysql如何根據(jù)漢字首字母排序
- Mysql row number()排序函數(shù)的用法和注意
- 兩種mysql對(duì)自增id重新從1排序的方法
- 數(shù)據(jù)庫(kù)查詢排序使用隨機(jī)排序結(jié)果示例(Oracle/MySQL/MS SQL Server)
- MySQL中按照多字段排序及問(wèn)題解決
- MySQL查詢優(yōu)化:連接查詢排序limit(join、order by、limit語(yǔ)句)介紹
- Mysql利用group by分組排序
- MySQL中一些鮮為人知的排序方式
相關(guān)文章
Mysql中in和exists的區(qū)別?&?not?in、not?exists、left?join的相互轉(zhuǎn)換問(wèn)題
這篇文章主要介紹了Mysql中in和exists的區(qū)別?&?not?in、not?exists、left?join的相互轉(zhuǎn)換,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09Navicat遠(yuǎn)程連接SQL Server并轉(zhuǎn)換成MySQL步驟詳解
最近遇到一個(gè)需求是將SQL Server轉(zhuǎn)換為 MySQL的格式,由于不想在本地安裝 SQL Server,所以決定在遠(yuǎn)程的 Windows 服務(wù)器上安裝,并在本地使用Navicat遠(yuǎn)程連接它,然而在實(shí)現(xiàn)過(guò)程中遇到了諸多問(wèn)題,記錄于此。感興趣的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-01-01mysql server is running with the --skip-grant-tables option
今天在mysql中新建數(shù)據(jù)庫(kù)提示The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement,原來(lái)是數(shù)據(jù)中配置的--skip-grant-tables,這樣安全就降低了,這個(gè)一般當(dāng)忘記root密碼的時(shí)候需要這樣操作2017-07-07mysql自動(dòng)備份多個(gè)數(shù)據(jù)庫(kù)的實(shí)現(xiàn)
本文主要介紹了mysql自動(dòng)備份多個(gè)數(shù)據(jù)庫(kù)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07MySQL命令行導(dǎo)出導(dǎo)入數(shù)據(jù)庫(kù)實(shí)例詳解
這篇文章主要介紹了MySQL命令行導(dǎo)出導(dǎo)入數(shù)據(jù)庫(kù)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2016-10-10MySQL數(shù)據(jù)庫(kù)Event定時(shí)執(zhí)行任務(wù)詳解
這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)Event定時(shí)執(zhí)行任務(wù)2017-12-12