Mysql怎么对字符串进行排序

时间:2022-12-06 01:09

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 |

+----+--------------+---------------------------+-------+---------+

标签:
随便看看
本类推荐
本类排行
热门标签

我国国家通讯社行不行啊细狗新年贺词祝福语2023年祝福语新年新年贺词新年贺词祝福语居家抗病毒小药箱除夕高速免费吗2022年除夕高速免费吗春联春联句子大全春联句子大全七字年夜饭十二道菜年夜饭十二道菜单年夜饭吃什么年夜饭吃什么菜吃年夜饭的寓意年夜饭黑芝麻菊花茶晒菊花茶腌腊肉送妈妈生日礼物汉白玉送闺蜜水钻送女人礼物爸爸生日送礼物送老公