1

Given this trades.xml:

<trades>
 <trade stock="ACO" price="200" time="12:00:00.1"/>
 <trade stock="ACO" price="202" time="12:00:00.2"/>
 <trade stock="BCO" price="200" time="12:00:00.3"/>
 <trade stock="CCO" price="300" time="12:00:00.4"/>
 <trade stock="CCO" price="299" time="12:00:00.5"/>
 <trade stock="CCO" price="290" time="12:00:00.6"/>
 <trade stock="ACO" price="200" time="12:00:00.7"/>
 <trade stock="ACO" price="205" time="12:00:03.1"/>
</trades>

Do you know why this query doesn't work? I'd like to have sliding windows of one second and to see how many trades with stock "AC0" have been sold in that windows of 1 second:

let $onesec := xs:dayTimeDuration('PT1S')
for sliding window $w
in doc("C:\Users\Lorenzo Enzino Vinci\Desktop\seminarioMontesi\trades.xml")//trade
start $s when $s/@stock eq "ACO"
end next $n when $n/@time > ($s/@time + $onesec) (: ******************** :)
let $occurrences := count ($w[@stock eq $s/@stock])where $occurrences gt 1
return <run stock="{$s/@stock}"
occurrences="{$occurrences}"
time="{$s/@time}"/>

When I try to execute, it says:

"[XPTY0004] '+' operator: number expected, xs:dayTimeDuration found."
at line with (: ******************** :)

So – how can I sum timestamps?

4

1 回答 1

2

当您要将持续时间 ( $onesec) 添加到字符串 ( $s/@time) 时会发生错误。将字符串(幸运的是采用适当的格式)转换为 time: $s/@time cast as xs:time + $onesec

于 2014-05-29T14:21:49.153 回答