1. 關于JSON_EXTRACT函數(shù)的使用揪罕,先貼一段代碼解釋:
SELECT DISTINCT json_extract(`Jdoc`, '$."Customer City Name"')
FROM `gc_master_data_0`
WHERE `Fiscal Year` = 2016
LIMIT 10
注釋:Jdoc是字段名离赫,"Customer City Name"是Jdoc字段中json文件中的key衫仑。Query結果如下:
2. 可以對提取的字段重新命名,代碼為:
SELECT DISTINCT json_extract(`Jdoc`, '$."Customer City Name"') AS `Customer City Name`
FROM `gc_master_data_0`
WHERE `Fiscal Year` = 2016
LIMIT 10
3. 當然這里有一個符號(->)可以用來替換函數(shù)功能鸣驱,代碼為:
SELECT DISTINCT `Jdoc`->'$."Customer City Name"' AS `Customer City Name`
FROM `gc_master_data_0`
WHERE `Fiscal Year` = 2016
LIMIT 10
實際上昼牛,
`Jdoc`->'$."Customer City Name"'
就是相當于表的一個字段术瓮,只不過這個字段是從Jdoc字段的json文件中提取。
4. 如果想獲取value的大小匾嘱,可以使用符號(->>)斤斧,貼代碼:
SELECT DISTINCT `Jdoc`->>'$."Customer City Name"' AS `Customer City Name`
FROM `gc_master_data_0`
WHERE `Fiscal Year` = 2016
LIMIT 10
Reference:
https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html