我在存储表路径的mysql表中有path字段。
它的页面ID末尾像33、31、121 ...
如何编写查询以仅获取ID?
Path
-----
trending-architectures/architecture_detail_page/31
trending-architectures/architecture_detail_page/33
trending-architectures/architecture_detail_page/33
trending-architectures/architecture_detail_page/33
trending-architectures/architecture_detail_page/33
最佳答案
如果模式相同,则可以使用功能substring_index()
mysql> select substring_index('trending-architectures/architecture_detail_page/31','/',-1) as num;
+-----+
| num |
+-----+
| 31 |
+-----+
1 row in set (0.00 sec)
所以选择语句将
select
substring_index(path,'/',-1) as number
from table_name
;