我是XQuery的新手,我的问题是关于不同的值,我使用以下代码来检索电影评论者
xquery version "1.0";
declare boundary-space preserve;
<result>
{for $reviews in doc("reviews.xml")/reviews/review,
$movie in doc("movies.xml")/movies/movie
where $reviews/movie_title = $movie/movie_title
and $movie//movie_genre = "Drama"
and $movie//month > 6
order by $reviews/movie_reviewer descending
return
(<reviewer>{distinct-values($reviews/movie_reviewer)}</reviewer>, '
')
}
</result>
以后我将代码更改为
xquery version "1.0";
declare boundary-space preserve;
<result>
{for $reviews in doc("reviews.xml")/reviews/review,
$movie in doc("movies.xml")/movies/movie
where $reviews/movie_title = $movie/movie_title
and $movie//movie_genre = "Drama"
and $movie//month > 6
return
{for $content in distinct-values($reviews/movie_reviewer)
order by $content descending
return (<reviewer>{$content}</reviewer>, '
')}
}
</result>
但我得到的结果与
相似 <result>
<reviewer>Wesley Barry</reviewer>
<reviewer>Michael Gordon</reviewer>
<reviewer>Michael Gordon</reviewer>
<reviewer>Michael Gordon</reviewer>
<reviewer>John Frankenheimer</reviewer>
<reviewer>J. Lee Thompson</reviewer>
<reviewer>J. Lee Thompson</reviewer>
<reviewer>Charles Walters</reviewer>
<reviewer>Charles Walters</reviewer>
</result>
我怎样才能使结果像
一样<result>
<reviewer>Wesley Barry</reviewer>
<reviewer>Michael Gordon</reviewer>
<reviewer>John Frankenheimer</reviewer>
<reviewer>J. Lee Thompson</reviewer>
<reviewer>Charles Walters</reviewer>
</result>
? 我知道这是非常基本的,但我不能明白这一点
答案 0 :(得分:0)
请关注@ Ranon的建议。但是,从您的查询中猜测:最简单的方法是使用XQuery 3.0和新的逐个语句。
xquery version "3.0";
declare boundary-space preserve;
<result>
{for $reviews in doc("reviews.xml")/reviews/review,
$movie in doc("movies.xml")/movies/movie
let $reviewer := $reviews/movie_reviewer
where $reviews/movie_title = $movie/movie_title
and $movie//movie_genre = "Drama"
and $movie//month > 6
group by $reviewer
order by $reviewer descending
return
(<reviewer>{$reviewer}</reviewer>, '
')
}
</result>