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

How to do a COUNT with conditions (IF or FILTER) in SPARQL

只有当 SPARQL 中的某些条件为真时,我才需要进行计数,像这样(不起作用):

SELECT ...
COUNT(FILTER(?qualisScoreValue = "A1")) ?QNTD_A1 .
COUNT(FILTER(?qualisScoreValue = "A2")) ?QNTD_A2 .
COUNT(FILTER(?qualisScoreValue = "B1")) ?QNTD_B1 .

我知道 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,

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

select (sum(if(condition, 1, 0)) as ?conditionCount) ...