MySQL甯歌鎺掑簭銆佽嚜瀹氫箟鎺掑簭鍜屾寜涓枃鎷奸煶瀛楁瘝鎺掑簭

1.甯歌鎺掑簭ASC DESC

ASC 姝e簭

DESC鍊掑彊

2.鑷畾涔夋帓搴�

鑷畾涔夋帓搴忔槸鏍规嵁鑷繁鎯宠鐨勭壒瀹氬瓧绗︿覆锛堟暟瀛楋級椤哄簭杩涜鎺掑簭銆�

涓昏鏄娇鐢ㄥ嚱鏁� FIELD(str,str1,str2,str3,...)

MySQL鐨勮嚜瀹氫箟鎺掑簭锛宻tr涓巗tr1銆乻tr2銆乻tr3...杩涜姣旇緝锛屽苟鎸夌収str1,str2,str3...鐨勯『搴忚緭鍑猴紝濡傛灉閬囧埌str涓簄ull鎴栬�呬笉瀛樺湪str1,str2,str3...涓殑鎯呭喌鐨勫垯搴忓垪涓�0

eg:select* from test order by field(type,2,3,1);

3.鎸変腑鏂囨嫾闊冲瓧姣嶆帓搴�

濡傛灉琛ㄥ瓧娈典娇鐢ㄧ殑GBK缂栫爜鐨勮瘽锛屾垜浠彲浠ョ洿鎺rder by value 锛屽洜涓篏BK鏈韩灏辨槸鎸夌収鎷奸煶瀛楁瘝鎺掑簭ABCDEFGHIGK...锛屽綋绗竴浣嶇浉鍚岀殑鏃跺�欎細姣旇緝绗簩浣嶏紝浠ユ绫绘帹銆� 濡傛灉琛ㄥ瓧娈典娇鐢ㄧ殑UTF-8缂栫爜鐨勮瘽锛岄�氬父鎴戜滑閮戒細鐨勭紪鐮侊紝杩欐牱鎴戜滑鍙互浣跨敤MySQL鐨刢onvert鏂规硶寮�杞崲gbk杩涜鎺掑簭銆�

eg:SELECT * FROM TEST ORDER BY CONVERT(value USING GBK) ASC/DESC

你可能感兴趣的:(MySQL甯歌鎺掑簭銆佽嚜瀹氫箟鎺掑簭鍜屾寜涓枃鎷奸煶瀛楁瘝鎺掑簭)