dqusbxh44823 2017-01-04 06:58
浏览 24

数据不从mysql json数据类型返回

I have search data from json field of mysql by where condition. but there are no data show.

MySql field name of "attributes_list" which is json type

My json data:

{
 "0": 
    {
      "id": "01c93aae-8603-42f3-b097-89357467872a#####ed20eb29-611a-4e5c-a966-c09708c98179", 
      "text": "Canada", 
      "attr_name": "Country"
    }, 
 "1": 
    {
      "id": "01c93aae-8603-42f3-b097-89357467872a#####6e6269a1-afbb-4d5d-b2ee-6d25fe38fec7", 
      "text": "Ontario", 
      "attr_name": "REGION"
    }, 
 "2": 
    {
      "id": "5a0a085e-f3e4-4fbe-9f3e-61cec4836d36#####d81923c9-9532-4375-ba3d-19214ac61c4e", 
      "text": "Lager", 
      "attr_name": "TYPE"
    }, 
 "-1": {"id": "", "text": "", "attr_name": ""}
}

My json query of mysql:

when I run following query then show data

SELECT * FROM products where attributes_list->'$[0]."0".text' = 'Canada';

but when I run this there are not show data

SELECT * FROM products where attributes_list->'$[0]."*".text' = 'Canada'; 

I explain my condition:

In product table there are 6 rows. In product table, there are a field which name attribute list.

This field is json type. There are save multiple attribute of a product. my attribute_list json format is

{"0":{"id":"","text":""},"1":{"id":"","text":""}}. 

Now I want to search where text='Canada' then read those product information

  • 写回答

1条回答 默认 最新

  • doushangan3690 2017-01-04 07:45
    关注

    According to mySql manual selector $**.text will come in use.

    [search for (the path $**.b) on the page to reach there.]

    This will search for second level of every document and will return the value of text key at second level. So your query will be like:

    SELECT * FROM products where attributes_list->'$.*.text' = 'Canada';
    

    Also I have tried to perform same task as you mentioned above in fiddle

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化