我有一张table card_percentage
,带ddl:
CREATE TABLE card_percentage
(
id int UNSIGNED AUTO_INCREMENT PRIMARY KEY,
jdoc json NULL
);
它有一行数据
id | jdoc
------------
1 | {"AMXC": [{"enabled": "y", "bank_code": "AMXC", "max_amount": 99999999.99, "min_amount": 0.0, "percentage": 2.5}], "VISA": [{"enabled": "y", "bank_code": "VISA", "max_amount": 1999.99, "min_amount": 0.0, "percentage": 2.8}, {"enabled": "y", "bank_code": "VISA", "max_amount": 99999999.99, "min_amount": 2000.0, "percentage": 1.8}]}
美化json的可读性
{
"AMXC": [
{
"enabled": "y",
"bank_code": "AMXC",
"min_amount": 0.0,
"max_amount": 99999999.99,
"percentage": 2.5
}
],
"VISA": [
{
"enabled": "y",
"bank_code": "VISA",
"min_amount": 0.0,
"max_amount": 1999.99,
"percentage": 2.8
},
{
"enabled": "y",
"bank_code": "VISA",
"min_amount": 2000.0,
"max_amount": 99999999.99,
"percentage": 1.8
}
]
}
现在我要选择 percentage
为了 VISA
当金额 200
介于 min_amount
以及 max_amount
. 为此,我使用以下查询,但它在结果集中没有给出任何结果。
SELECT id,
jdoc -> '$.VISA[*].percentage' percentage
FROM card_percentage
WHERE id = 1
AND jdoc -> '$.VISA[*].min_amount' <= 200
AND jdoc -> '$.VISA[*].max_amount' >= 200
;
1条答案
按热度按时间yshpjwxd1#
基于@akina关于使用json表的评论,我做了进一步的研究。
下面是我的查询,效果非常好。
为了使这项工作正常进行,这篇文章“json_table–两全其美”真的很有帮助。