这是mysql中的JSON
[
{
"debt_type": "Personal loan",
"amount_borrowed": "2100",
"repayment_amount": "179",
"remaining_balance": "1900",
"repayment_frequency": "Fortnightly",
"financial_institution": "Money3"
},
{
"debt_type": "Commercial loan",
"amount_borrowed": "2700",
"repayment_amount": "199",
"remaining_balance": "1200",
"repayment_frequency": "Fortnightly",
"financial_institution": "Money3"
}
]
什么SQL查询来查找应用程序ID,其中bond_type =“ Commericial_loan” AND amount_borrowed> 2300 AND剩余余额<30000
这是表结构
Id | application_id | debts (JSON data mentioned above)
我写的查询是这个
SELECT application_id FROM `table_name`
where json_contains(debts, '{"debt_type" : "Commercial loan" , "amount_borrowed": "2700"}')
但是此查询对amount_borrowed取2700的精确值,如何添加大于或小于条件
编辑开始
这是我尝试过的另一个查询,但结果为空,应该会查询此查询以找到应用程序ID,其中amount_borrowed在100-20000和loan_type =商业贷款之间,但结果为空
SELECT id, application_id FROM `table_name`
where
debts REGEXP '{"loan_type":"Commercial loan", "amount_borrowed":"(1[0-9][0-9][0-9]|2000)"}'
编辑结束