[英]SPARQL group by and order by: not ordered
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.我跟进查询,其中 schema.org 数据库用于查找类的子级数量 - 作为比我的应用程序更简单的数据库。 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
gives给
schema:PublicationEvent "OnDemandEvent BroadcastEvent"
schema:UserInteraction "UserPageVisits UserComments UserPlays UserBlocks UserDownloads UserPlusOnes UserLikes UserCheckins UserTweets"
Which is not alphabetically ordered.这不是按字母顺序排列的。 If I replace the sort order to
desc
the result is exactly the same.如果我将排序顺序替换为
desc
,结果完全相同。 I seem not to understand how group by
, order by
and possibly bind
interact.我似乎不明白
group by
、 order by
和可能的bind
交互的。
An additional select
subquery is required to push the order inside the groups:需要一个额外的
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 GroupConcat : 18.5.1.7 组连接:
The order of the strings is not specified.
未指定字符串的顺序。
From the horse's mouth : 从马嘴里说:
On 2011-04-22, at 19:01, Steve Harris wrote:
在 2011-04-22 的 19:01,史蒂夫哈里斯写道:
On 2011-04-22, at 06:18, Jeen Broekstra wrote:
在 2011-04-22 的 06:18,Jeen Broekstra 写道:
However, looking at the SPARQL 1.1 query spec, I think this is not a guaranteed result: as far as I can tell the solution modifier
ORDER BY
should be applied to the solution sequence after grouping and aggregation, so it can not influence the order of the input for theGROUP_CONCAT
.但是,查看 SPARQL 1.1 查询规范,我认为这不是一个有保证的结果:据我所知,解决方案修饰符
ORDER BY
应该应用于分组和聚合后的解决方案序列,因此它不会影响解决方案的顺序GROUP_CONCAT
的输入。That's correct.
没错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.