Mysql怎样对字符串进行排序
Mysql对字符串进行排序的方法示例:
利用ORDER BY关键字进行排序。
语法:
SELECT column_name,column_name
FROM table_name
ORDER BY column_name,column_name ASC|DESC;
示例:
假定有一个Websites表数据以下:
+----+--------------+---------------------------+-------+---------+
| id | name | url | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA |
| 2 | 淘宝 | https://www.taobao.com/ | 13 | CN |
| 3 | 微博 | http://weibo.com/ | 20 | CN |
| 4 | Facebook | https://www.facebook.com/ | 3 | USA |
+----+--------------+---------------------------+-------+---------+
进行排序:
SELECT * FROM Websites ORDER BY alexa asc;//ASC为升序,DESC为降序,默许是升序
结果:
+----+--------------+---------------------------+-------+---------+
| id | name | url | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA |
| 5 | Facebook | https://www.facebook.com/ | 3 | USA |
| 2 | 淘宝 | https://www.taobao.com/ | 13 | CN |
| 4 | 微博 | http://weibo.com/ | 20 | CN |
+----+--------------+---------------------------+-------+---------+
本文来源:https://www.yuntue.com/post/58480.html | 云服务器网,转载请注明出处!