List OrientDB中嵌入列表的范围日期时间查询
我在OrientDB中有这样一个结构,其中每个节点都是由user_id表示的特定用户,他们的所有购买信息都保存在嵌入列表中,如下所示List OrientDB中嵌入列表的范围日期时间查询,list,range,orientdb,List,Range,Orientdb,我在OrientDB中有这样一个结构,其中每个节点都是由user_id表示的特定用户,他们的所有购买信息都保存在嵌入列表中,如下所示 [ { "user_id": 1, "purchase_info": [ { "product_id": 100, "timestamp": "2016-04-26 01:50:00" },
[
{
"user_id": 1,
"purchase_info": [ {
"product_id": 100,
"timestamp": "2016-04-26 01:50:00"
},
{
"product_id": 200,
"timestamp": "2016-04-26 10:50:00"
}
]
},
{
"user_id": 2,
"purchase_info": [ {
"product_id": 100,
"timestamp": "2016-04-26 10:50:00"
},
{
"product_id": 300,
"timestamp": "2016-04-26 20:50:00"
}
]
},
{
"user_id": 3,
"purchase_info": [ {
"product_id": 100,
"timestamp": "2016-04-26 04:50:00"
}
]
},
{
"user_id": 4,
"purchase_info": [ {
"product_id": 300,
"timestamp": "2016-04-26 05:50:00"
}
]
}
]
现在我想查找在特定日期时间范围内购买产品的用户。
例如,如果日期时间范围介于2016-04-26 01:00:00和2016-04-26 04:55:00之间,则返回的结果将是用户id 1和3
我知道要查询嵌入式列表,我们需要使用WHERE IN
。但是,我找不到使用该格式的范围的方法
对于时间戳的非范围查询,也不能使用asDateTime()
例如,此查询不返回任何内容:
SELECT from V where "2016-04-26 01:50:00" in purchase_info.timestamp.asDateTime()
这不是使用OrientDB的最佳方式
select expand( inV() )
from purchase
where date between "2016-04-26 01:00:00" and "2016-04-26 04:55:00"
要获取在此时间间隔购买的所有用户,请执行以下操作:
select expand( outV() )
from purchase
where date between "2016-04-26 01:00:00" and "2016-04-26 04:55:00"
在这段时间内销售所有产品
要获得良好的性能,请记住使用非唯一索引为边缘“购买”中的日期字段编制索引。尝试以下操作:
select user_id,date from (select user_id,purchase_info.timestamp as date from User unwind date) where date between "2016-04-26 01:00:00" and "2016-04-26 04:55:00"
结果:
希望能有帮助