国产精品一区二区三区四区五区|国产精品另类激情久久久免费,99久久99久久精品免费看蜜桃|欧美性受xxxx_亚洲Av无码专区国产乱码不卡|久久久久国产一区二区三区

返回頂部
關(guān)閉軟件導(dǎo)航
位置:首頁(yè) > 資訊 > 其他>說(shuō)說(shuō)MySQL ORDER BY

  在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é)

如果您覺(jué)得 說(shuō)說(shuō)MySQL ORDER BY 這篇文章對(duì)您有用服務效率,請(qǐng)分享給您的好友,謝謝
文章地址:http://61py.com/article/other/ssMySQLORDERBY.html
解放雙手無(wú)盡可能,有問(wèn)題添加天線(xiàn)貓微信
曲阳县| 大渡口区| 农安县| 丹阳市| 赫章县| 高尔夫| 得荣县| 沂南县| 辽宁省| 兴业县| 洞口县| 雅安市| 英德市| 北流市| 雅安市| 新竹县| 巴里| 开阳县| 邛崃市| 海淀区| 英山县| 盐山县| 太仆寺旗| 泰兴市| 宝兴县| 车险| 和林格尔县| 三都| 墨竹工卡县| 江永县| 玉环县| 赤水市| 宁明县| 广元市| 阆中市| 永嘉县| 施甸县| 大关县| 会同县| 望江县| 玉环县|