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

时间:2016-05-31 00:10:15

标签: 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,

1 个答案:

答案 0 :(得分:3)

而不是计数,使用 sum if 函数。如,

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