Orientdb SubQuery Max Date
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Orientdb SubQuery Max Date相关的知识,希望对你有一定的参考价值。
我搜索过这个并没有太多运气。我在OrientDb(3.0.2)中有一个图形数据库设置,并且我遇到了一些subquerys的问题。我可以在经典的关系数据库中轻松编写。我玩过LET和$ parent / $ children,但这些概念仍然有点令人困惑。
三个顶点:实体< - 检查 - >违规
我希望每个实体的最后一次检查(日期),并知道有多少违规与该检查相关联。
我知道如何为每次检查提取违规数量(边缘的大小())。我也知道如何拉动每个实体的最大检验日期,但将这两个实体结合起来是一件很困难的事情。有什么想法吗?谢谢!
更新:我想我越来越接近,但仍然不确定如何进行“内部”联接。不确定我是否完全理解$ parent / $ current变量的工作原理。此查询不起作用
SELECT
entityId
,$a.num_violations
,max(Date) as mDate
FROM (
SELECT
@rid AS entityId
,in('COMPLETED_AT').Date as Date
FROM Entity
unwind Date
)
let $a = (
SELECT
Date
,out('FOUND_DURING').size() as num_violations
FROM Inspection
WHERE $parent.mDate = Date
AND $parent.entityId in out('COMPLETED_AT').@rid
)
GROUP BY entityId
,$a.num_violations
答案
试试这个:
select expand($c)
let $a = (select date, out("link")[@class="Violations"].size() as num_violations from Inspection),
$b = (select name, max(date) as max_date from (select name, in("link").date as date from Entity unwind date) group by name),
$c = unionAll($a, $b)
这就是你得到的:
+----+-------------------+--------------+----------+-------------------+
|# |date |num_violations|name |max_date |
+----+-------------------+--------------+----------+-------------------+
|0 |2018-08-31 00:00:00|1 | | |
|1 |2018-08-30 00:00:00|2 | | |
|2 |2018-08-29 00:00:00|1 | | |
|3 | | |entity_001|2018-08-31 00:00:00|
|4 | | |entity_002|2018-08-29 00:00:00|
+----+-------------------+--------------+----------+-------------------+
UPDATE
select expand($c)
let $a = (select name as entity_name, max(date) as max_date from (select name, in("link").date as date from Entity unwind date) group by name),
$b = (select out("link")[@class="Violations"].size() as num_violations from Inspection),
$c = unionAll($a, $b)
+----+-----------+-------------------+--------------+
|# |entity_name|max_date |num_violations|
+----+-----------+-------------------+--------------+
|0 |entity_001 |2018-08-31 00:00:00| |
|1 |entity_002 |2018-08-29 00:00:00| |
|2 | | |1 |
|3 | | |2 |
|4 | | |1 |
+----+-----------+-------------------+--------------+
希望能帮助到你
问候
以上是关于Orientdb SubQuery Max Date的主要内容,如果未能解决你的问题,请参考以下文章
OrientDB 和 PostgreSQL JDBC 驱动程序发生冲突(InvocationTargetException):除了 JDBC 之外,是不是有一个包含所有内容的 OrientDB JAR