duanfang2708 2013-11-25 23:16
浏览 52
已采纳

如何查询以查找字符串中的特定文本并在其旁边抓取部分?

Trying to understand LEFT and LOCATE with mysql to help me process a string

I have text that contains a bunch of data and within it is

street_num="9716", street_name=

I need to extract just the street num

so I was trying to do

SELECT LEFT( newdata, LOCATE( 'street_name=', 'newdata' ) ) 
FROM `uploadTracker` 
WHERE `type` =0

in that example I would like it to return 9716

  • 写回答

1条回答 默认 最新

  • drqwbh2150 2013-11-25 23:57
    关注

    In situations like this function SUBSTRING_INDEX() becomes very handy

    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(newdata, 'street_num="', -1), '"', 1) street_num
      FROM uploadTracker
     WHERE type = 0
    

    Output:

    | STREET_NUM |
    |------------|
    |       9716 |
    

    Here is SQLFiddle demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi