我有3个主要类的模式:Transaction,Address和ValueTx(Edge)。
我试图在一段时间内找到连接的组件。
现在我正在基于此查询(OrientDB: connected components OSQL query)执行此查询:
SELECT distinct(traversedElement(0)) from ( TRAVERSE both('ValueTx') from (select * from Transaction where height >= 402041 and height <= 402044))
这将使“头部”摆脱掉。每个trasversal和它做另一个DFS我可以得到我想要搜索的连接组件的每个节点和边缘。
我如何使用上面的查询获取连接组件中的事务数量以及它们的值的总和? (tx的值是Transaction类的属性)
我想做类似的事情:
SELECT distinct(traversedElement(0)) as head, count(Transaction), sum(valueTot) from ( TRAVERSE both('ValueTx') from (select * from Transaction where height >= 402041 and height <= 402044)) group by head
但当然不行。我只得到一行最后一个头和所有交易的总和。
提前致谢。
编辑:
这是我正在寻找的一个例子:
每个交易都在相同的高度范围内: 使用我的查询(我的帖子中的第一个)我摆脱了通过几个地址链接的每组事务的第一个节点。 例如:
#15:27
#15:28
#15:30
#15:34
#15:35
#15:36
#15:37
#15:41
#15:47
#15:53
我想要得到的是每个第一个节点的列表,其中交易总数(不仅仅是交易)属于它所属的群组和每笔交易的价值总和(存储在类交易中的valueTot。
EDIT2: 这是我正在进行测试的数据集: 主要的问题是我有很多数据和我之前尝试的方法(从每个摆脱我做出不同的SQL查询)它很慢,我希望有一个更快的方法。 EDIT3: 这是一个更新的示例数据库:Download (注意,它比另一个更大)
select head, sum(valueTot) as valueTot, count(*) as numTx,sum(miner) as minerCount from (SELECT *,traversedElement(0) as head from ( TRAVERSE both('ValueTx') from (select * from Transaction where height >= 0 and height <= 110000 ) while ( @class = 'Address' or (@class = 'Transaction' and height >= 0 and height <= 110000 )) ) where @class = 'Transaction' ) group by head
我的系统上的这个查询大约花了一分钟,如果我限制结果集,所以我认为问题可能在内部查询中选择不使用索引的事务...你有吗?任何想法?
答案 0 :(得分:1)
您可以使用此查询
select @rid, $a[0].sum as sumValueTot ,$a[0].count as countTransaction from Transaction
let $a = ( select sum(valueTot),count(*) from (TRAVERSE both('ValueTx') from $parent.$current) where @class="Transaction")
where height >= 402041 and height <= 402044
希望它有所帮助。
答案 1 :(得分:0)
这是你在寻找什么?
select head, sum(valueTot), count(*) from (SELECT *,traversedElement(0) as head from ( TRAVERSE both('ValueTx') from (select * from Transaction where height >= 402041 and height <= 402044)) where @class = "Transaction") group by head