进行排序?
基本上我有一些数据:
:student1 :hasAScore "4.1"
:student2 :hasAScore "2.7"
:student2 :hasBScore "2.1"
但是在我的查询中,我想
select * where{
?a :hasAScore ?score1
?b :hasBScore ?score2
//bind ?score1 as ?score and bind ?score2 as ?score too, so they can be ranked by "order by"
} order by(?score)
基本上我是说我希望能够通过分数对学生进行排名,分数可以是AScore或BScore。是否可以将?score1和?score2并集为?score,这样我就可以根据?score
是否存在score1和score2的并集作为?分数,以便我可以按?分数进行排名
当然,您可以使用适当命名的union
,如下所示。我假设你的意思是同一个学生既有A分又有B分,所以你实际上想要一个变量在主题位置。
select * where {
{ ?student :hasAScore ?score }
union
{ ?student :hasBScore ?score }
}
你甚至不需要在这里使用union
。在SPARQL 1.1中,引入了属性路径,这意味着您可以编写:hasScoreA|:hasScoreB
,如:
select * where {
?student :hasAScore|:hasBScore ?score
}