發(fā)布時(shí)間:2020-12-03
欄目:其他
在MySQL里,ORDER BY可以有幾種玩法mysql文件入庫(kù)工具廣泛應用?
先看下手冊(cè)里的說(shuō)明:
SELECT [ALL | DISTINCT | DISTINCTROW ].... [ORDER BY {col_name | expr | position} [ASC | DESC], ...]
也就是關註度,有三種ORDER BY模式,下面分別簡(jiǎn)單演示下哪些領域。
測(cè)試表:
[yejr]@[imysql.com]>show create table t1G*************************** 1. row *************************** Table: t1Create Table: CREATE TABLE `t1` ( `c1` int(10) unsigned NOT NULL DEFAULT '0', `c2` int(10) unsigned NOT NULL DEFAULT '0', `c3` int(10) unsigned NOT NULL DEFAULT '0', `c4` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`c1`)mysql文章入庫(kù)軟件, KEY `c2` (`c2`)) ENGINE=InnoDB DEFAULT CHARSET=utf8[yejr]@[imysql.com]>select * from t1;+----+----+----+-----+| c1 | c2 | c3 | c4 |+----+----+----+-----+| 0 | 0 | 0 | 0 || 1 | 1 | 1 | 0 || 3 | 3 | 3 | 0 || 4 | 2 | 2 | 0 || 6 | 8 | 5 | 123 || 7 | 6 | 6 | 123 || 10 | 10 | 4 | 123 |+----+----+----+-----+例1. 按指定列名ORDER BY [yejr]@[imysql.com]>select * from t1 order by c2;+----+----+----+-----+| c1 | c2 | c3 | c4 |+----+----+----+-----+| 0 | 0 | 0 | 0 || 1 | 1 | 1 | 0 || 4 | 2 | 2 | 0 || 3 | 3 | 3 | 0 || 7 | 6 | 6 | 123 || 6 | 8 | 5 | 123 || 10 | 10 | 4 | 123 |+----+----+----+-----+例2. 按指定序號(hào)的列排序 #按第二個(gè)列排序(同例1)[yejr]@[imysql.com]>select * from t1 order by 2;+----+----+----+-----+| c1 | c2 | c3 | c4 |+----+----+----+-----+| 0 | 0 | 0 | 0 || 1 | 1 | 1 | 0 || 4 | 2 | 2 | 0 || 3 | 3 | 3 | 0 || 7 | 6 | 6 | 123 || 6 | 8 | 5 | 123 || 10 | 10 | 4 | 123 |+----+----+----+-----+#按第三個(gè)列排序[yejr]@[imysql.com]>select * from t1 order by 3;+----+----+----+-----+| c1 | c2 | c3 | c4 |+----+----+----+-----+| 0 | 0 | 0 | 0 || 1 | 1 | 1 | 0 || 4 | 2 | 2 | 0 || 3 | 3 | 3 | 0 || 10 | 10 | 4 | 123 || 6 | 8 | 5 | 123 || 7 | 6 | 6 | 123 |+----+----+----+-----+例3. 根據(jù)表達(dá)式排序 #ORDER BY c3=3 DESCmysql文件入庫(kù)工具 敢於挑戰,也就是如果某條記錄c3=3,則它排在第一位#其他非c3=3的記錄建立和完善,則按照聚集索引的順序顯示[yejr]@[imysql.com]>select * from t1 order by c3=3 desc;+----+----+----+-----+| c1 | c2 | c3 | c4 |+----+----+----+-----+| 3 | 3 | 3 | 0 || 0 | 0 | 0 | 0 || 1 | 1 | 1 | 0 || 4 | 2 | 2 | 0 || 6 | 8 | 5 | 123 || 7 | 6 | 6 | 123 || 10 | 10 | 4 | 123 |+----+----+----+-----+#甚至還可以用case when#這個(gè)例子中MySQL文章入庫(kù)助手 提供了遵循,當(dāng)c3=3時(shí),會(huì)被重置成10大型,其余按照實(shí)際值倒序排[yejr]@[imysql.com]>select * from t1 order by case when c3=3 then 10 else c3 end desc;+----+----+----+-----+| c1 | c2 | c3 | c4 |+----+----+----+-----+| 3 | 3 | 3 | 0 || 7 | 6 | 6 | 123 || 6 | 8 | 5 | 123 || 10 | 10 | 4 | 123 || 4 | 2 | 2 | 0 || 1 | 1 | 1 | 0 || 0 | 0 | 0 | 0 |+----+----+----+-----+小結(jié)
文章地址:http://61py.com/article/other/ssMySQLORDERBY.html

- 1通王CMS 2.0簡(jiǎn)介
- 2黑帽網(wǎng)站排名檢測(cè)
- 3MySQL中經(jīng)典的too many connection怎么破
- 4網(wǎng)易郵箱洪陸駕:反垃圾郵件需集合全球力量
- 5站群友鏈換鏈神器
- 6云勢(shì)軟件VirgoEDC助力安徽萬(wàn)邦能力建設、迪時(shí)咨詢(xún)等公司臨床試驗(yàn)數(shù)據(jù)采集智能化
- 7Authorize 屬性通過(guò)聲明的方式保護(hù)控制器或其部分方法
- 8域名是稀有資源模樣,好的域名,在一定時(shí)期內(nèi)會(huì)越來(lái)越升值
- 9解析常見(jiàn)的PHP緩存技術(shù)有哪些
- 10對(duì)ASP.NET程序員非常有用工具