gpt4 book ai didi

mysql - 从 json 字段 mysql 中的键、值对列表中提取一个键

转载 作者:可可西里 更新时间:2023-11-01 08:38:47 26 4
gpt4 key购买 nike

我有以下格式的数据:

"article_body" : [
{
"article_desc" : "THURSDAY, Sept. 1, 2016 (HealthDay News) -- Dapagliflozin improves insulin sensitivity and increases lipid oxidation and plasma ketone concentration in patients with type 2 diabetes mellitus (T2DM), according to a study published online Aug. 25 in Diabetes Care. \n\n Giuseppe Daniele",
"links" : [{
"link_name" : "Full Text (subscription or payment may be required)"}
]}
],

我要提取 key

article_desc

来自 article_body

我在 Mysql 中的代码片段:

SELECT 

JSON_EXTRACT(full_article_json, '$.article_body."article_desc"') AS description,
FROM
wc_article_full_data;

我收到空数据,如何解析此类数据?

最佳答案

你的key = 'article_body'是一个数组JSON,所以你需要使用索引获取数据。

你可以试试这个。

模式(MySQL v5.7)

CREATE TABLE wc_article_full_data(

full_article_json JSON
);

insert into wc_article_full_data values (
'{"article_body" : [
{
"article_desc" : "THURSDAY, Sept. 1, 2016 (HealthDay News) -- Dapagliflozin improves insulin sensitivity and increases lipid oxidation and plasma ketone concentration in patients with type 2 diabetes mellitus (T2DM), according to a study published online Aug. 25 in Diabetes Care. Giuseppe Daniele",
"links" : [{
"link_name" : "Full Text (subscription or payment may be required)"}
]}
]}');

查询#1

SELECT JSON_EXTRACT(full_article_json,'$.article_body[0].article_desc') AS descriptio
FROM wc_article_full_data;

| descriptio |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| "THURSDAY, Sept. 1, 2016 (HealthDay News) -- Dapagliflozin improves insulin sensitivity and increases lipid oxidation and plasma ketone concentration in patients with type 2 diabetes mellitus (T2DM), according to a study published online Aug. 25 in Diabetes Care. Giuseppe Daniele" |

View on DB Fiddle

如果你想从 article_body 数组中获取 article_desc 的所有值。你可以尝试在索引中使用*

SELECT JSON_EXTRACT(full_article_json,'$.article_body[*].article_desc') AS descriptio
FROM wc_article_full_data

关于mysql - 从 json 字段 mysql 中的键、值对列表中提取一个键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52474199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com