dougekui1518 2019-07-06 12:01
浏览 244
已采纳

在mysql json列中搜索[重复]

This question already has an answer here:

I have a column contain json data,

{
"city":"\u0628\u063a\u062f\u0627\u062f",
"town":"\u0627\u0644\u0627\u0639\u0638\u0645\u064a\u0629",
"queue":"316",
"lane":"22",
"home":"15"
}

how can I search on the object (town) in the table? I have tried

$query ="SELECT * FROM tabel WHERE JSON_CONTAINS(colom_name,'town') like  '%$Word%'  order by id DESC";

Also There are no results at all

</div>
  • 写回答

2条回答 默认 最新

  • drzrzzkh462254 2019-07-06 13:24
    关注

    We are using JSON fields in one of our projects, and for example, we have everything related to a user in one column, called simply JSON. So in order to search easier for a specific user, we are using JSON_EXTRACT. So for your example, you could do it like:

    SELECT * FROM Table_Name WHERE JSON_EXTRACT(<json_column>,'$.town') LIKE '%something%'
    

    You could even get town name, or city, by doing it like this:

    SELECT JSON_EXTRACT(<json_column>,'$.<filed_from_json>') FROM Table_Name WHERE JSON_EXTRACT(<json_column>,'$.town') LIKE '%something%'
    

    BR

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀