【发布时间】:2021-01-11 15:28:09
【问题描述】:
我的一张表中连续有 json 数据。现在我想以编程方式将数据选择到表中。现在我只有提供原始 json 数据才能实现。
我现在要做的是:
SELECT
attribute_name,
attribute_value
FROM
JSON_TABLE ( '[json data should be fetched here from a table by using select]', '$[*]' COLUMNS ( attribute_name VARCHAR ( 255 ) PATH '$.attribute_name', attribute_value VARCHAR ( 255 ) PATH '$.attribute_value' ) ) AS attributes_table
获取数据的查询是:
SELECT
attributes
FROM
tbl_items_pricing_attributes
WHERE
tbl_items_pricing_attributes.branch_id = '1001'
AND tbl_items_pricing_attributes.sku_code = '1000010003'
查询的结果是:
[{"attribute_name":"size","attribute_value":"large","buy_price":500.0,"sell_price":700.0,"price_is_taxable":true},{"attribute_name":"size","attribute_value":"medium","buy_price":400.0,"sell_price":600.0,"price_is_taxable":true},{"attribute_name":"size","attribute_value":"small","buy_price":300.0,"sell_price":500.0,"price_is_taxable":true}]
【问题讨论】:
标签: mysql sql arrays json unnest