On 21/03/14 17:56, Cindy A McMullen wrote:
I have a query like this: (assume prefixes are defined)
"SELECT DISTINCT  ?opportunity ?status " +
                 "WHERE { ?u w:role \"Sales Rep\" . ?u w:participatedIn ?opportunity . 
?opportunity w:customer \"IBM\" .  " +
                 " ?opportunity w:status ?status ." +
                 "}";

That returns expected values:
[{opportunity=http://www.oracle.com/osn/osn.owl#Opportunity41, 
status=Open^^http://www.w3.org/2001/XMLSchema#string}, 
{opportunity=http://www.oracle.com/osn/osn.owl#Opportunity40, 
status=Open^^http://www.w3.org/2001/XMLSchema#string}, 
{opportunity=http://www.oracle.com/osn/osn.owl#Opportunity30, 
status=Lost^^http://www.w3.org/2001/XMLSchema#string}, 
{opportunity=http://www.oracle.com/osn/osn.owl#Opportunity48, 
status=Open^^http://www.w3.org/2001/XMLSchema#string}, 
{opportunity=http://www.oracle.com/osn/osn.owl#Opportunity6, 
status=Lost^^http://www.w3.org/2001/XMLSchema#string}, 
{opportunity=http://www.oracle.com/osn/osn.owl#Opportunity18, 
status=Lost^^http://www.w3.org/2001/XMLSchema#string}]

What I'd like to do is to count the number of 'Lost' and 'Open' values for this 
query, so I have this:

"SELECT ?status (count (?status) as ?scount) " +
                 "WHERE { ?u w:role \"Sales Rep\" . ?u w:participatedIn ?opportunity . 
?opportunity w:customer \"IBM\" .  " +
                 " ?opportunity w:status ?status ." +
                 "} GROUP BY ?status";

But the counts are wrong:

In what way?

You have a DISTINCT over ?opportunity ?status in the first query. Rows may have been removed.


[{status=Lost^^http://www.w3.org/2001/XMLSchema#string, 
scount=5^^http://www.w3.org/2001/XMLSchema#integer}, 
{status=Open^^http://www.w3.org/2001/XMLSchema#string, 
scount=7^^http://www.w3.org/2001/XMLSchema#integer}]

-----

How can I fix the above query to return the correct counts?

COUNT(DISTINCT ...)

but it is DISTINCT over the COUNT expression, not the pairs
(?opportunity, ?status)

What is

SELECT ?opportunity ?status (count (distinct *) AS ?c) {
...}
GROUP BY ?opportunity ?status

        Andy


Thanks -

-- Cindy


Reply via email to