Perfect, James, thanks for the example!  Here's the query that works:

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



On Mar 21, 2014, at 1:21 PM, james anderson wrote:

> good evening;
> 
> 
> On 21 Mar 2014, at 20:11, Cindy A McMullen <[email protected]> wrote:
> 
>> Thanks, James.  Can you give an example?
> 
> look here 
> 
>    http://dydra.com/jhacker/foaf/sparql#subquery
> 
> the dataset content is not meaningfull wrt the query, but it gives the idea.
> 
>> 
>> On Mar 21, 2014, at 1:00 PM, james anderson wrote:
>> 
>>> try a subselect with the distinct feeding into the outer select with the 
>>> aggregation.
>>> 
>>> On 21 Mar 2014, at 18:56, Cindy A McMullen <[email protected]> 
>>> 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:
>>>> 
>>>> [{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?
>>>> 
>>>> Thanks -
>>>> 
>>>> -- Cindy
>>> 
>>> ---
>>> james anderson | [email protected] | http://dydra.com
>>> 
>>> 
>>> 
>>> 
>>> 
>> 
> 
> ---
> james anderson | [email protected] | http://dydra.com
> 
> 
> 
> 
> 

Reply via email to