Xquery:给定时间戳加1秒

时间:2014-05-29 12:40:54

标签: xquery xquery-3.0

鉴于此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>

你知道为什么这个查询不起作用吗?我希望有一秒钟的推拉窗口,看看有多少交易有库存&#34; AC0&#34;已经在1秒的窗口出售:

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}"/>

当我尝试执行时,它说:

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

那么 - 我如何总结时间戳?

1 个答案:

答案 0 :(得分:2)

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