![](/img/trans.png)
[英]SPARQL CONTRUCT ordered list with ORDER BY and GROUP 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 by
、 order 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
未指定字符串的顺序。
在 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.