SPARQL分组依据和排序依据:未排序 [英] SPARQL group by and order by: not ordered
本文介绍了SPARQL分组依据和排序依据:未排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我会跟踪查询其中schema.org数据库用于查找类的子级数-作为比我的应用程序更简单的数据库.我想获得按字母顺序连接的孩子的名字.查询:
I follow up on query where the schema.org database is used to find the number of children of a class - as a simpler database than my application. I want to get the names of the children concatenated in alphabetic order. The query:
prefix schema: <http://schema.org/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?child (group_concat (?string) as ?strings)
where {
?child rdfs:subClassOf schema:Event .
?grandchild rdfs:subClassOf ?child .
bind (strafter(str(?grandchild), "http://schema.org/") as ?string)
} group by ?child order by asc(?string)
limit 20
给予
schema:PublicationEvent "OnDemandEvent BroadcastEvent"
schema:UserInteraction "UserPageVisits UserComments UserPlays UserBlocks UserDownloads UserPlusOnes UserLikes UserCheckins UserTweets"
哪个不是按字母顺序排列的.如果将排序顺序替换为desc
,则结果完全相同.我似乎不明白group by
,order by
和可能的bind
是如何相互作用的.
Which is not alphabetically ordered. If I replace the sort order to desc
the result is exactly the same. I seem not to understand how group by
, order by
and possibly bind
interact.
推荐答案
还需要一个附加的select
子查询才能将顺序推入组中
An additional select
subquery is required to push the order inside the groups:
prefix schema: <http://schema.org/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?child (group_concat (?string) as ?strings)
where {
select *
{
?child rdfs:subClassOf schema:Event .
?grandchild rdfs:subClassOf ?child .
bind (strafter(str(?grandchild), "http://schema.org/") as ?string)
} order by asc(?string)
} group by ?child
limit 20
这篇关于SPARQL分组依据和排序依据:未排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文