源数据

[{"attrId":2762280,"attrValueId":3475578},{"attrId":2762279,"attrValueId":3475579}]

MySQL SQL 处理 JSON 数据

目的:提取出 json 中的 attrValueId

case 1

select 
JSON_EXTRACT(t.`saleAttrValues`, '$[*].attrValueId') as tt
from `sp_unifiedsku` t
where t.`unifiedProductId` = 252329
and t.status = 0
group by tt

MySQL SQL 处理 JSON 数据

case 2

group by 用来去重

这里的$[0]指的是取 case 1 的第一个元素

select 
JSON_EXTRACT(JSON_EXTRACT(t.`saleAttrValues`, '$[*].attrValueId'), '$[0]') as tt
from `sp_unifiedsku` t
where t.`unifiedProductId` = 252329
and t.status = 0
group by tt

MySQL SQL 处理 JSON 数据

case 3

将id拼接起来

select GROUP_CONCAT(tt) from (select 
JSON_EXTRACT(JSON_EXTRACT(t.`saleAttrValues`, '$[*].attrValueId'), '$[0]') as tt
from `sp_unifiedsku` t
where t.`unifiedProductId` = 252329
and t.status = 0
group by tt) as ttt

MySQL SQL 处理 JSON 数据

相关文章:

  • 2021-08-05
  • 2021-08-13
  • 2021-07-11
  • 2021-12-12
  • 2021-11-14
  • 2021-12-16
  • 2022-02-28
猜你喜欢
  • 2022-12-23
  • 2022-01-08
  • 2021-06-10
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案