我有一个数据库字段,其中包含一个非常特定格式的值。
当我执行以下基本 sql 查询时:
SELECT post_content FROM wp_posts LIMIT 5
它返回以下结果集:
[download id="5219"]
[download id="953"]
[download id="958"]
[download id="3907"]
[download id="3909"]
我需要编辑查询,使其只返回字符串的数值。所以 - 而不是返回: [download id="5219"]
,我希望它返回 5219
这可能吗?
提前致谢:)
最佳答案
我认为最简单的方法是使用substring_index()
。以下将以数字形式返回值:
select substring_index(post_content, '"', 2) + 0
以下为字符串:
select substring_index(substring_index(post_content, '"', 2), '"', -1)
关于php - 选择字段值的一部分 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26976680/