簡體   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