如何在 SPARQL 中使用条件(IF 或 FILTER)进行 COUNT

San*_*tyl 4 sparql

仅当 SPARQL 中某些条件成立时,我才需要进行计数,如下所示(不起作用):

SELECT ...
COUNT(FILTER(?qualisScoreValue = "A1")) ?QNTD_A1 .
COUNT(FILTER(?qualisScoreValue = "A2")) ?QNTD_A2 .
COUNT(FILTER(?qualisScoreValue = "B1")) ?QNTD_B1 .
Run Code Online (Sandbox Code Playgroud)

我了解 mysql,我认为在 mysql 语言的情况下,我需要的应该是等效的,如下所示(有效):

select ...
count(case when q.nameQualis = 'A1' then 1 else null end) as qntd_A1,
count(case when q.nameQualis = 'A2' then 1 else null end) as qntd_A2,
count(case when q.nameQualis = 'B1' then 1 else null end) as qntd_B1,
Run Code Online (Sandbox Code Playgroud)

Jos*_*lor 6

为此,请使用sumif函数,而不是count 。例如,

select (sum(if(condition, 1, 0)) as ?conditionCount) ...
Run Code Online (Sandbox Code Playgroud)