Dear James Anderson ! Its a great favour from you. Thank you very much. How can I get oid of that offer which have minimum price / at-least one offer id per product?
Thank you again. Regards Nauman On Sun, Jul 26, 2015 at 3:35 PM, buehmann < [email protected]> wrote: > You still don't get the usage of GROUP BY in SPARQL I guess. > You have to return the ?pid variable not only GROUP BY it. The reason is > that the ?pid has to be projected to the outer query. > > And once you use GROUP BY, you can only return aggregates (min, max, etc) > or variables that you're grouping by. That means, you have also to group by > the ?condition variable. > > Lorenz > > > On 26.07.2015 11:18, Nauman Ramzan wrote: > >> Hi Buehmann ! >> I am using GROUP BY ?pid inside inner-query as well as outer-query >> Like >> >> PREFIX mod:<http://www.example.com/datam/op/> >>> PREFIX prod:<http://www.example.com/products/> >>> SELECT DISTINCT ?pid (?title )(?count)# (?condition) >>> FROM <http://www.example.com/products> >>> WHERE { >>> ?pid dprop:productTitle ?title. >>> ?pid dprop:productDescription ?description. >>> { >>> SELECT (COUNT(?oid) AS ?count) #(?condition) >>> >> FROM <http://www.example.com/offers> WHERE { ?oid oprop:isOfferOf >> >>> ?pid. ?oid dprop:condition ?condition. } GROUP BY ?pid >>> >> } >> >>> } >>> GROUP BY ?pid >>> >> >> I am still getting duplicate ?pid. >> Second problem is I also wanted to get ?condition but if I'll un-comment >> ?condition then compiler is showing this error >> >> Variable ?condition is used in the result set outside aggregate and not >> >>> mentioned in GROUP BY clause >>> >> >> Can you please help me to correct this query. >> >> Thank you. >> >> On Sun, Jul 26, 2015 at 1:02 PM, buehmann < >> [email protected]> wrote: >> >> What Andy means is that the pid variable of the subselect is not bound to >>> the outer query. Sub-SELECTs are evaluated first, those values have to be >>> propagated/projected to the outer query, otherwise you don't get the >>> intended values. >>> It's so simple add >>> GROUP BY ?pid >>> >>> to the sub-SELECT and also add >>> >>> SELECT ... ?pid >>> >>> Lorenz >>> >>> >>> On 26.07.2015 08:36, Nauman Ramzan wrote: >>> >>> Dear Andy Good Morning ! >>>> Can you please explain more. How can I fix this problem ? >>>> Because >>>> in outer query I am getting ?pid one by one. in sub query instead of >>>> taking >>>> value from outer query subquery is taking value of ?pid from VALUES. >>>> >>>> My Problem I want to get Product information and counts of new and used >>>> >>>> offers against each product. >>>>> >>>>> Thank you. >>>> Regards >>>> Nauman >>>> >>>> On Sat, Jul 25, 2015 at 9:06 PM, Andy Seaborne <[email protected]> wrote: >>>> >>>> On 25/07/15 12:09, Nauman Ramzan wrote: >>>> >>>>> Dear Andy, >>>>> >>>>>> I am using Jena ARQ. >>>>>> >>>>>> On Sat, Jul 25, 2015 at 3:02 PM, Nauman Ramzan < >>>>>> [email protected]> >>>>>> wrote: >>>>>> >>>>>> Hi James Anderson ! >>>>>> >>>>>> Thank you for your help. >>>>>>> Now construct this query >>>>>>> >>>>>>> CONSTRUCT{ >>>>>>> >>>>>>> ?pid dprop:title ?title; >>>>>>> >>>>>>>> dprop:description ?description; >>>>>>>> dprop:brand ?brand; >>>>>>>> dprop:isPublic ?isPublic; >>>>>>>> dprop:count ?total; >>>>>>>> dprop:priceMin ?priceMin; >>>>>>>> dprop:condition ?condition; >>>>>>>> dprop:createdAt ?createdAt. >>>>>>>> } >>>>>>>> WHERE { >>>>>>>> ?pid dprop:productTitle ?title; >>>>>>>> dprop:productDescription ?description; >>>>>>>> dprop:productBrand ?brand; >>>>>>>> dprop:isPublic ?isPublic; >>>>>>>> dprop:createdAt ?createdAt. >>>>>>>> OPTIONAL { ?pid dprop:bulletpoint0 ?bulletpoint0 } >>>>>>>> OPTIONAL { ?pid dprop:bulletpoint1 ?bulletpoint1 } >>>>>>>> { >>>>>>>> SELECT (COUNT(?cond) AS ?total) (MIN(?pr) AS ?priceMin ) >>>>>>>> ?condition WHERE{ >>>>>>>> ?pid ^mod:isOfferOf ?oid. >>>>>>>> ?oid dprop:price ?pr. >>>>>>>> ?oid dprop:condition ?cond. >>>>>>>> BIND (if( ?cond = 1, "New", "Used") AS ?condition). >>>>>>>> } >>>>>>>> } >>>>>>>> VALUES ?pid { prod:Rl5RVl5R prod:Rl5RVl5Q prod:Rl5RVl5W >>>>>>>> prod:Rl5RVl5Y >>>>>>>> prod:Rl5RVl5U } >>>>>>>> } >>>>>>>> >>>>>>>> >>>>>>>> Everything is working fine. except sub-query calculation error. >>>>>>> result >>>>>>> of >>>>>>> total is not correct. >>>>>>> >>>>>>> That maybe because there are 2 different ?pid variables. >>>>>>> >>>>>> SELECT (COUNT(?cond) AS ?total) (MIN(?pr) AS ?priceMin ) >>>>> >>>>>> ?condition WHERE{ >>>>>>>> ?pid ^mod:isOfferOf ?oid. >>>>>>>> ?oid dprop:price ?pr. >>>>>>>> ?oid dprop:condition ?cond. >>>>>>>> BIND (if( ?cond = 1, "New", "Used") AS ?condition). >>>>>>>> } >>>>>>>> >>>>>>>> ?pid is not projected out so it is not joined with the one in the >>>>>>> >>>>>> VALUEs >>>>> clause. You could GROUP BY ?pid and add it to the SELECT clause. You >>>>> can >>>>> also just have >>>>> >>>>> WHERE { >>>>> SELECT ... { ... } >>>>> GROUP BY ?pid >>>>> } >>>>> >>>>> with everything inside the SELECT's {} >>>>> >>>>> Andy >>>>> >>>>> >>>>> My schema(relation between product and offer ) you can see in first >>>>> >>>>> message. >>>>>> >>>>>>> On Sat, Jul 25, 2015 at 1:00 PM, Andy Seaborne <[email protected]> >>>>>>> wrote: >>>>>>> >>>>>>> On 25/07/15 04:54, Nauman Ramzan wrote: >>>>>>> >>>>>>> Hi Here is my question in details. Now i am getting counts and >>>>>>>> other >>>>>>>> >>>>>>>> info. >>>>>>>>> but i want to define/use this result as data of outer block. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> http://answers.semanticweb.com/questions/32850/sparql-use-subquery-as-resultvariable-for-outer-query >>>>>>>>> same as >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> http://stackoverflow.com/questions/31586989/sparql-use-subquery-as-result-variable-for-outer-query >>>>>>>>> Thank you. >>>>>>>>> >>>>>>>>> >>>>>>>>> The query isn't legal SPARQL (parse error - non-group'ed >>>>>>>>> variables >>>>>>>>> >>>>>>>> in >>>>>>>> the >>>>>>>> inner select - even after completing the prefixes). Previously, you >>>>>>>> indicated you were using Virtuoso. Their support lists are on >>>>>>>> SourceForge. >>>>>>>> >>>>>>>> It will help them to have a complete, minimal example. >>>>>>>> >>>>>>>> A small amount of data >>>>>>>> A complete working query >>>>>>>> >>>>>>>> Andy >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Tue, Jul 21, 2015 at 5:04 PM, Andy Seaborne <[email protected]> >>>>>>>> >>>>>>>> wrote: >>>>>>>>> >>>>>>>>> On 21/07/15 11:35, Nauman Ramzan wrote: >>>>>>>>> >>>>>>>>> Hi all ! >>>>>>>>> >>>>>>>>>> I have this type of data >>>>>>>>>> >>>>>>>>>>> <offer1> rdf:isOfferOf <product1> >>>>>>>>>>> >>>>>>>>>>> <offer2> rdf:isOfferOf <product1> >>>>>>>>>>> >>>>>>>>>>> <offer3> rdf:isOfferOf <product2> >>>>>>>>>>>> <offer4> rdf:isOfferOf <product2> >>>>>>>>>>>> >>>>>>>>>>>> <offer5> rdf:isOfferOf <product2> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> <offer7> rdf:isOfferOf <product7> >>>>>>>>>>>> >>>>>>>>>>> now I want to get all offers of product1, product2. >>>>>>>>>>> second counts of offers. >>>>>>>>>>> Thank you >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> What have you tried? >>>>>>>>>>> >>>>>>>>>>> A complete, minimal example of what you have tried makes it >>>>>>>>>>> >>>>>>>>>> easier to >>>>>>>>>> answer the question. >>>>>>>>>> >>>>>>>>>> Andy >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >
