下面是我的样本要求
我想要的客户满足以下条件
- 在国家"xyz",代之间的2019年至2021年。
- 应当具有至少一个账户之间的平衡10000和13000和分是"abc"和交易的日期之间的20200110和20210625. 它的格式和存储数
- 应当具有至少一个地址在的状态"状态1"和pin码之间625001和625015
下表结构
CREATE TABLE IF NOT EXISTS customer_search_ms.customer
(
customer_id integer,
customer_details jsonb
)
有可能是数以百万计的行表中。 我已经创建了杜松子酒指标的类型jsonb_ops在customer_details柱作为我们还要检查是否存在条件和范围比较
下面是一个样本数据在customer_data JSONB列
customer_id : 1
{
"customer_data": {
"name": "abc",
"incorporated_year": 2020,
"country":"xyz",
"account_details": [
{
"transaction_dates": [
20180125, 20190125, 20200125,20200525
],
"account_id": 1016084,
"account_balance": 2000,
"account_branch": "xyz"
},
{
"transaction_dates": [
20180125, 20190125, 20200125
],
"account_id": 1016087,
"account_balance": 12010,
"account_branch": "abc"
}
],
"address": [
{
"address_id": 24739,
"door_no": 4686467,
"street_name":"street1",
"city": "city1",
"state": "state1",
"pin_code": 625001
},
{
"address_id": 24730,
"door_no": 4686442,
"street_name":"street2",
"city": "city1",
"state": "state1",
"pin_code": 625014
}
]
}
}
现在的查询,我已经写上
SELECT c.customer_id,
c.customer_details
FROM customer_search_ms.customer c
WHERE c.customer_details @@ CAST('$.customer_data.country == "xyz" && $.customer_data.incorporated_year >= 2019 && $.customer_data.incorporated_year <= 2021 ' AS JSONPATH)
AND c.customer_details @? CAST('$.customer_data.account_details[*] ? (@.account_balance >= 10000) ? (@.account_balance <= 13000) ?(@.account_branch == "abc") ? (@.transaction_dates >= 20200110) ? (@.transaction_dates <= 20210625)' AS JSONPATH)
AND c.customer_details @? CAST('$.customer_data.address[*] ? (@.state == "state1") ? (@.pin_code >= 625001) ? (@.pin_code <= 625015) ' AS JSONPATH)
处理上述情况是这最好的方式编写。 是否有可能把所有的3个标准的(客户/帐户或地址)成一个表情? 该表将有数以百万计的行中。 我的意见具有它作为一个表达和打击该数据库将得到最好的业绩。 是否有可能结合这3条件作为一种表达