Re: sum property values
There have been 2 different techniques mentioned that solve different problems. The SUM aggregate function can be used to reduce a result set as illustrated by the following minimal CSV snippets: BEFORE: ?v1,?v2 "A",1 "A",1 "A",2 "B",3 "B",1 AFTER: ?v1,?v3 "A",4 "B",4 The above results could be achieved by: SELECT ?v1 (SUM(?v2) AS ?v3) WHERE { #pattern that binds ?v1 and ?v2 } GROUP BY ?v1 If you want to extend a result set with a new binding composed from other bound values, you could use: SELECT ?v1 ?v2 ?v3 ?v4 WHERE { #pattern that binds ?v1,?v2,?v3 BIND (?v2+?v3 AS ?v4) } If the basic graph pattern results were: ?v1,?v2,?v3 "A",2,0 "B",1,3 "C",5,2 then the BIND statement would cause: ?v1,?v2,?v3,?v4 "A",2,0,2 "B",1,3,4 "C",5,2,7 Regards, --Paul > On Oct 11, 2016, at 13:32, neha gupta wrote: > > I am still waiting for any response about how to add/sum values of > different data property values in SPARQL? > > > >> On Sun, Oct 9, 2016 at 8:19 AM, neha gupta wrote: >> >> yes because what I studied about SUM is it sum the values of single >> variable. >> >> SELECT (?worldcupgoals + ?eurogoals+ ?othergoals)) >> where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals ?worldcupgoals; >> ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} >> >> On Sun, Oct 9, 2016 at 5:15 AM, Lorenz B. > leipzig.de> wrote: >> >>> No, that's obviously wrong. And you don't need GROUP BY and SUM - in >>> your examples it's even the wrong way. >>> Simply SELECT the team and use '+' to compute the sum of the different >>> goal values. >>> >>> And why can't you try it out? >>> Will it works like: SELECT (SUM(?worldcupgoals ?eurogoals ?othergoals)) where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals >>> ?worldcupgoals; ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} On Sat, Oct 8, 2016 at 12:43 PM, Martynas Jusevičius < >>> marty...@graphity.org> wrote: > https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggr >>> egateExample > > On Sat, Oct 8, 2016 at 9:35 PM, neha gupta >>> wrote: >> I am sorry but need some details? I really have no idea how to sum > multiple >> values (data properties) using SPARQL, despite searched the web. >> >> On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne >>> wrote: >> >>> SUM and GROUP BY >>> >>> Andy >>> >>> On 08/10/16 19:14, neha gupta wrote: team1 WorldCup_Goals 20 team1 EuroCup_Goals 25 team1 Other_Goals50 WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. How to calculate total goals of team1 using SPARQL? >>> -- >>> Lorenz Bühmann >>> AKSW group, University of Leipzig >>> Group: http://aksw.org - semantic web research center >>
Re: sum property values
@Martynas He wants to get the sum of multiple data property values per team, i.e. the values come from different properties and therefore are assigned to different variables indeed. I don't think that GROUP BY + SUM makes sense in that case, but (?val1 + ?val2 + ?val3) should work. The questions is why he doesn't try it out. On 12.10.2016 14:13, Martynas Jusevičius wrote: > If you had tried to execute your query, or at least parse it with > http://sparql.org/query-validator.html, you would know that > > SUM(?worldcupgoals ?eurogoals ?othergoals) > > is not a valid syntax. > > You wanted an example, and I gave you a link to an example from the > official spec. Does it show SUM() being used with multiple variables > in one expression? No. So why are you attempting that? > > > > On Wed, Oct 12, 2016 at 2:08 PM, neha gupta wrote: >> No I have not tried it yet because Lorenz sir, you did not endorse it in >> the last email. >> Now I will try it. >> >> On Wed, Oct 12, 2016 at 12:18 AM, Lorenz B. < >> buehm...@informatik.uni-leipzig.de> wrote: >> >>> I do not understand. You already have the answer and your query does >>> what you want. What is the problem now? Did you try the query? >>> I am still waiting for any response about how to add/sum values of different data property values in SPARQL? On Sun, Oct 9, 2016 at 8:19 AM, neha gupta >>> wrote: > yes because what I studied about SUM is it sum the values of single > variable. > > SELECT (?worldcupgoals + ?eurogoals+ ?othergoals)) > where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals >>> ?worldcupgoals; > ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} > > On Sun, Oct 9, 2016 at 5:15 AM, Lorenz B. leipzig.de> wrote: > >> No, that's obviously wrong. And you don't need GROUP BY and SUM - in >> your examples it's even the wrong way. >> Simply SELECT the team and use '+' to compute the sum of the different >> goal values. >> >> And why can't you try it out? >> >>> Will it works like: >>> >>> SELECT (SUM(?worldcupgoals ?eurogoals ?othergoals)) >>> where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals >> ?worldcupgoals; >>> ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} >>> >>> >>> On Sat, Oct 8, 2016 at 12:43 PM, Martynas Jusevičius < >> marty...@graphity.org> >>> wrote: >>> https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggr >> egateExample On Sat, Oct 8, 2016 at 9:35 PM, neha gupta >> wrote: > I am sorry but need some details? I really have no idea how to sum multiple > values (data properties) using SPARQL, despite searched the web. > > On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne >> wrote: >> SUM and GROUP BY >> >> Andy >> >> >> On 08/10/16 19:14, neha gupta wrote: >> >>> team1 WorldCup_Goals 20 >>> team1 EuroCup_Goals 25 >>> team1 Other_Goals50 >>> >>> WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. >>> >>> How to calculate total goals of team1 using SPARQL? >>> >>> >> -- >> Lorenz Bühmann >> AKSW group, University of Leipzig >> Group: http://aksw.org - semantic web research center >> >> >>> -- >>> Lorenz Bühmann >>> AKSW group, University of Leipzig >>> Group: http://aksw.org - semantic web research center >>> >>>
Re: sum property values
If you had tried to execute your query, or at least parse it with http://sparql.org/query-validator.html, you would know that SUM(?worldcupgoals ?eurogoals ?othergoals) is not a valid syntax. You wanted an example, and I gave you a link to an example from the official spec. Does it show SUM() being used with multiple variables in one expression? No. So why are you attempting that? On Wed, Oct 12, 2016 at 2:08 PM, neha gupta wrote: > No I have not tried it yet because Lorenz sir, you did not endorse it in > the last email. > Now I will try it. > > On Wed, Oct 12, 2016 at 12:18 AM, Lorenz B. < > buehm...@informatik.uni-leipzig.de> wrote: > >> I do not understand. You already have the answer and your query does >> what you want. What is the problem now? Did you try the query? >> >> > I am still waiting for any response about how to add/sum values of >> > different data property values in SPARQL? >> > >> > >> > >> > On Sun, Oct 9, 2016 at 8:19 AM, neha gupta >> wrote: >> > >> >> yes because what I studied about SUM is it sum the values of single >> >> variable. >> >> >> >> SELECT (?worldcupgoals + ?eurogoals+ ?othergoals)) >> >> where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals >> ?worldcupgoals; >> >> ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} >> >> >> >> On Sun, Oct 9, 2016 at 5:15 AM, Lorenz B. > >> leipzig.de> wrote: >> >> >> >>> No, that's obviously wrong. And you don't need GROUP BY and SUM - in >> >>> your examples it's even the wrong way. >> >>> Simply SELECT the team and use '+' to compute the sum of the different >> >>> goal values. >> >>> >> >>> And why can't you try it out? >> >>> >> Will it works like: >> >> SELECT (SUM(?worldcupgoals ?eurogoals ?othergoals)) >> where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals >> >>> ?worldcupgoals; >> ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} >> >> >> On Sat, Oct 8, 2016 at 12:43 PM, Martynas Jusevičius < >> >>> marty...@graphity.org> >> wrote: >> >> > https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggr >> >>> egateExample >> > On Sat, Oct 8, 2016 at 9:35 PM, neha gupta >> >>> wrote: >> >> I am sorry but need some details? I really have no idea how to sum >> > multiple >> >> values (data properties) using SPARQL, despite searched the web. >> >> >> >> On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne >> >>> wrote: >> >>> SUM and GROUP BY >> >>> >> >>> Andy >> >>> >> >>> >> >>> On 08/10/16 19:14, neha gupta wrote: >> >>> >> team1 WorldCup_Goals 20 >> team1 EuroCup_Goals 25 >> team1 Other_Goals50 >> >> WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. >> >> How to calculate total goals of team1 using SPARQL? >> >> >> >>> -- >> >>> Lorenz Bühmann >> >>> AKSW group, University of Leipzig >> >>> Group: http://aksw.org - semantic web research center >> >>> >> >>> >> -- >> Lorenz Bühmann >> AKSW group, University of Leipzig >> Group: http://aksw.org - semantic web research center >> >>
Re: sum property values
No I have not tried it yet because Lorenz sir, you did not endorse it in the last email. Now I will try it. On Wed, Oct 12, 2016 at 12:18 AM, Lorenz B. < buehm...@informatik.uni-leipzig.de> wrote: > I do not understand. You already have the answer and your query does > what you want. What is the problem now? Did you try the query? > > > I am still waiting for any response about how to add/sum values of > > different data property values in SPARQL? > > > > > > > > On Sun, Oct 9, 2016 at 8:19 AM, neha gupta > wrote: > > > >> yes because what I studied about SUM is it sum the values of single > >> variable. > >> > >> SELECT (?worldcupgoals + ?eurogoals+ ?othergoals)) > >> where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals > ?worldcupgoals; > >> ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} > >> > >> On Sun, Oct 9, 2016 at 5:15 AM, Lorenz B. >> leipzig.de> wrote: > >> > >>> No, that's obviously wrong. And you don't need GROUP BY and SUM - in > >>> your examples it's even the wrong way. > >>> Simply SELECT the team and use '+' to compute the sum of the different > >>> goal values. > >>> > >>> And why can't you try it out? > >>> > Will it works like: > > SELECT (SUM(?worldcupgoals ?eurogoals ?othergoals)) > where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals > >>> ?worldcupgoals; > ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} > > > On Sat, Oct 8, 2016 at 12:43 PM, Martynas Jusevičius < > >>> marty...@graphity.org> > wrote: > > > https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggr > >>> egateExample > > On Sat, Oct 8, 2016 at 9:35 PM, neha gupta > >>> wrote: > >> I am sorry but need some details? I really have no idea how to sum > > multiple > >> values (data properties) using SPARQL, despite searched the web. > >> > >> On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne > >>> wrote: > >>> SUM and GROUP BY > >>> > >>> Andy > >>> > >>> > >>> On 08/10/16 19:14, neha gupta wrote: > >>> > team1 WorldCup_Goals 20 > team1 EuroCup_Goals 25 > team1 Other_Goals50 > > WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. > > How to calculate total goals of team1 using SPARQL? > > > >>> -- > >>> Lorenz Bühmann > >>> AKSW group, University of Leipzig > >>> Group: http://aksw.org - semantic web research center > >>> > >>> > -- > Lorenz Bühmann > AKSW group, University of Leipzig > Group: http://aksw.org - semantic web research center > >
Re: sum property values
I do not understand. You already have the answer and your query does what you want. What is the problem now? Did you try the query? > I am still waiting for any response about how to add/sum values of > different data property values in SPARQL? > > > > On Sun, Oct 9, 2016 at 8:19 AM, neha gupta wrote: > >> yes because what I studied about SUM is it sum the values of single >> variable. >> >> SELECT (?worldcupgoals + ?eurogoals+ ?othergoals)) >> where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals ?worldcupgoals; >> ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} >> >> On Sun, Oct 9, 2016 at 5:15 AM, Lorenz B. > leipzig.de> wrote: >> >>> No, that's obviously wrong. And you don't need GROUP BY and SUM - in >>> your examples it's even the wrong way. >>> Simply SELECT the team and use '+' to compute the sum of the different >>> goal values. >>> >>> And why can't you try it out? >>> Will it works like: SELECT (SUM(?worldcupgoals ?eurogoals ?othergoals)) where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals >>> ?worldcupgoals; ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} On Sat, Oct 8, 2016 at 12:43 PM, Martynas Jusevičius < >>> marty...@graphity.org> wrote: > https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggr >>> egateExample > On Sat, Oct 8, 2016 at 9:35 PM, neha gupta >>> wrote: >> I am sorry but need some details? I really have no idea how to sum > multiple >> values (data properties) using SPARQL, despite searched the web. >> >> On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne >>> wrote: >>> SUM and GROUP BY >>> >>> Andy >>> >>> >>> On 08/10/16 19:14, neha gupta wrote: >>> team1 WorldCup_Goals 20 team1 EuroCup_Goals 25 team1 Other_Goals50 WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. How to calculate total goals of team1 using SPARQL? >>> -- >>> Lorenz Bühmann >>> AKSW group, University of Leipzig >>> Group: http://aksw.org - semantic web research center >>> >>> -- Lorenz Bühmann AKSW group, University of Leipzig Group: http://aksw.org - semantic web research center
Re: sum property values
I am still waiting for any response about how to add/sum values of different data property values in SPARQL? On Sun, Oct 9, 2016 at 8:19 AM, neha gupta wrote: > yes because what I studied about SUM is it sum the values of single > variable. > > SELECT (?worldcupgoals + ?eurogoals+ ?othergoals)) > where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals ?worldcupgoals; > ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} > > On Sun, Oct 9, 2016 at 5:15 AM, Lorenz B. leipzig.de> wrote: > >> No, that's obviously wrong. And you don't need GROUP BY and SUM - in >> your examples it's even the wrong way. >> Simply SELECT the team and use '+' to compute the sum of the different >> goal values. >> >> And why can't you try it out? >> >> > Will it works like: >> > >> > SELECT (SUM(?worldcupgoals ?eurogoals ?othergoals)) >> > where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals >> ?worldcupgoals; >> > ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} >> > >> > >> > On Sat, Oct 8, 2016 at 12:43 PM, Martynas Jusevičius < >> marty...@graphity.org> >> > wrote: >> > >> >> https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggr >> egateExample >> >> >> >> On Sat, Oct 8, 2016 at 9:35 PM, neha gupta >> wrote: >> >>> I am sorry but need some details? I really have no idea how to sum >> >> multiple >> >>> values (data properties) using SPARQL, despite searched the web. >> >>> >> >>> On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne >> wrote: >> >>> >> SUM and GROUP BY >> >> Andy >> >> >> On 08/10/16 19:14, neha gupta wrote: >> >> > team1 WorldCup_Goals 20 >> > team1 EuroCup_Goals 25 >> > team1 Other_Goals50 >> > >> > WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. >> > >> > How to calculate total goals of team1 using SPARQL? >> > >> > >> -- >> Lorenz Bühmann >> AKSW group, University of Leipzig >> Group: http://aksw.org - semantic web research center >> >> >
Re: sum property values
yes because what I studied about SUM is it sum the values of single variable. SELECT (?worldcupgoals + ?eurogoals+ ?othergoals)) where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals ?worldcupgoals; ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} On Sun, Oct 9, 2016 at 5:15 AM, Lorenz B. < buehm...@informatik.uni-leipzig.de> wrote: > No, that's obviously wrong. And you don't need GROUP BY and SUM - in > your examples it's even the wrong way. > Simply SELECT the team and use '+' to compute the sum of the different > goal values. > > And why can't you try it out? > > > Will it works like: > > > > SELECT (SUM(?worldcupgoals ?eurogoals ?othergoals)) > > where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals > ?worldcupgoals; > > ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} > > > > > > On Sat, Oct 8, 2016 at 12:43 PM, Martynas Jusevičius < > marty...@graphity.org> > > wrote: > > > >> https://www.w3.org/TR/2013/REC-sparql11-query-20130321/# > aggregateExample > >> > >> On Sat, Oct 8, 2016 at 9:35 PM, neha gupta > wrote: > >>> I am sorry but need some details? I really have no idea how to sum > >> multiple > >>> values (data properties) using SPARQL, despite searched the web. > >>> > >>> On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne > wrote: > >>> > SUM and GROUP BY > > Andy > > > On 08/10/16 19:14, neha gupta wrote: > > > team1 WorldCup_Goals 20 > > team1 EuroCup_Goals 25 > > team1 Other_Goals50 > > > > WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. > > > > How to calculate total goals of team1 using SPARQL? > > > > > -- > Lorenz Bühmann > AKSW group, University of Leipzig > Group: http://aksw.org - semantic web research center > >
Re: sum property values
No, that's obviously wrong. And you don't need GROUP BY and SUM - in your examples it's even the wrong way. Simply SELECT the team and use '+' to compute the sum of the different goal values. And why can't you try it out? > Will it works like: > > SELECT (SUM(?worldcupgoals ?eurogoals ?othergoals)) > where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals ?worldcupgoals; > ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} > > > On Sat, Oct 8, 2016 at 12:43 PM, Martynas Jusevičius > wrote: > >> https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggregateExample >> >> On Sat, Oct 8, 2016 at 9:35 PM, neha gupta wrote: >>> I am sorry but need some details? I really have no idea how to sum >> multiple >>> values (data properties) using SPARQL, despite searched the web. >>> >>> On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne wrote: >>> SUM and GROUP BY Andy On 08/10/16 19:14, neha gupta wrote: > team1 WorldCup_Goals 20 > team1 EuroCup_Goals 25 > team1 Other_Goals50 > > WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. > > How to calculate total goals of team1 using SPARQL? > > -- Lorenz Bühmann AKSW group, University of Leipzig Group: http://aksw.org - semantic web research center
Re: sum property values
Will it works like: SELECT (SUM(?worldcupgoals ?eurogoals ?othergoals)) where { ?team rdf:type ont:Team . ?team ont:WorldCup_Goals ?worldcupgoals; ont:EuroCup_Goals ?eurogoals ; ont:Other_Goals ?othergoals} On Sat, Oct 8, 2016 at 12:43 PM, Martynas Jusevičius wrote: > https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggregateExample > > On Sat, Oct 8, 2016 at 9:35 PM, neha gupta wrote: > > I am sorry but need some details? I really have no idea how to sum > multiple > > values (data properties) using SPARQL, despite searched the web. > > > > On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne wrote: > > > >> SUM and GROUP BY > >> > >> Andy > >> > >> > >> On 08/10/16 19:14, neha gupta wrote: > >> > >>> team1 WorldCup_Goals 20 > >>> team1 EuroCup_Goals 25 > >>> team1 Other_Goals50 > >>> > >>> WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. > >>> > >>> How to calculate total goals of team1 using SPARQL? > >>> > >>> >
Re: sum property values
https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#aggregateExample On Sat, Oct 8, 2016 at 9:35 PM, neha gupta wrote: > I am sorry but need some details? I really have no idea how to sum multiple > values (data properties) using SPARQL, despite searched the web. > > On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne wrote: > >> SUM and GROUP BY >> >> Andy >> >> >> On 08/10/16 19:14, neha gupta wrote: >> >>> team1 WorldCup_Goals 20 >>> team1 EuroCup_Goals 25 >>> team1 Other_Goals50 >>> >>> WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. >>> >>> How to calculate total goals of team1 using SPARQL? >>> >>>
Re: sum property values
I am sorry but need some details? I really have no idea how to sum multiple values (data properties) using SPARQL, despite searched the web. On Sat, Oct 8, 2016 at 11:21 AM, Andy Seaborne wrote: > SUM and GROUP BY > > Andy > > > On 08/10/16 19:14, neha gupta wrote: > >> team1 WorldCup_Goals 20 >> team1 EuroCup_Goals 25 >> team1 Other_Goals50 >> >> WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. >> >> How to calculate total goals of team1 using SPARQL? >> >>
Re: sum property values
SUM and GROUP BY Andy On 08/10/16 19:14, neha gupta wrote: team1 WorldCup_Goals 20 team1 EuroCup_Goals 25 team1 Other_Goals50 WorldCup_Goals, EuroCup_Goals and Other_Goals are my properties. How to calculate total goals of team1 using SPARQL?