2016-04-13 36 views
-1

我試圖一次顯示三個不同的變量。 這是我試過的。如何在Xquery中只顯示一次變量?

  let $totalmovies := count(//Movies/Movie) 
     let $averagevariton:=(count(//Movies/Movie/secondtitles/OtherTitleName) + count(//Movies/Movie/Title)) div $totalmovies 

     for $m in //Movies/Movie 
     let $year := (max($m/secondtitles/Year) - min($m/secondtitles/Year))+1 

     order by $year descending 

     return ($totalmovies,$averagevariton,$year) 

但目前,它不斷打印值直到for循環完成。我怎樣才能顯示這些值只有一次?

回答

0

目前尚不清楚正確的輸出應該是什麼,也許你想使用for僅環填充$year變量,像這樣:

let $totalmovies := count(//Movies/Movie) 
let $averagevariton:= (count(//Movies/Movie/secondtitles/OtherTitleName) + count(//Movies/Movie/Title)) div $totalmovies 
let $year := 
    for $m in //Movies/Movie 
    let $diff := (max($m/secondtitles/Year) - min($m/secondtitles/Year))+1 
    order by $diff descending 
    return $diff 
return ($totalmovies,$averagevariton,$year) 
+0

喜,有輸出沒一年。 – user2775042

+0

@ user2775042請發佈簡化的XML示例和預期的輸出。這個答案是我能夠(也是願意)猜測的最遠的。謝謝 – har07

+0

對不起,因爲我的錯,沒有一年。 – user2775042