Sparql BIND result of count WITH A VARIABLE

后端 未结 1 1949
长发绾君心
长发绾君心 2021-01-27 10:24

Is there any way to bind the result of count to a variable? I\'ve tried the following (which doesn\'t work):



        
1条回答
  •  有刺的猬
    2021-01-27 10:39

    COUNT is an aggregate function and may be used only to define projected variables. To count all matches, your specific example should read:

    SELECT ( COUNT(?s) AS ?totalSubject ) WHERE {
    
        ?s ?p ?o. 
    
    }
    

    However, aggregate functions are usually applied to groups of matches. For instance, to count subjects grouped by type:

    SELECT ?t ( COUNT(?s) AS ?totalSubject ) WHERE {
    
         ?s a ?t.
    
    } GROUP BY ?t
    

    Be aware that when using aggregate functions your query is subject to some restrictions: selected variables must be either

    • simple variables included in GROUP BY; or
    • aggregates or constant values.

    0 讨论(0)
提交回复
热议问题