繁体   English   中英

SPARQL group by 和 order by:未排序

[英]SPARQL group by and order by: not ordered

我跟进查询,其中 schema.org 数据库用于查找类的子级数量 - 作为比我的应用程序更简单的数据库。 我想按字母顺序连接孩子的名字。 查询:

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 byorder by和可能的bind交互的。

需要一个额外的select子查询来推送组内的订单:

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 

18.5.1.7 组连接

未指定字符串的顺序。


从马嘴里说

在 2011-04-22 的 19:01,史蒂夫哈里斯写道:

在 2011-04-22 的 06:18,Jeen Broekstra 写道:

但是,查看 SPARQL 1.1 查询规范,我认为这不是一个有保证的结果:据我所知,解决方案修饰符ORDER BY应该应用于分组和聚合的解决方案序列,因此它不会影响解决方案的顺序GROUP_CONCAT的输入。

没错。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM