![](/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.