From: Peter Brawley Date: July 1 2006 3:50pm Subject: Re: need one query List-Archive: http://lists.mysql.com/mysql/199560 Message-Id: <44A699B7.1020601@earthlink.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=======AVGMAIL-44A699B851BF=======" --=======AVGMAIL-44A699B851BF======= Content-Type: multipart/alternative; boundary=------------010905050702070801070705 --------------010905050702070801070705 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit >orgunit parent value >12 10 x >15 12 y >16 12 z >17 12 p > Now here 15,16, and 17 are the children of 12 and 12 is the >child of 10.Now i need a query which gives the sum of all the children of >12 and nturn 12 itself . i.e I need the sum(values(15+16+17+12)).Is there a >query which gives the sum of all these.It will be very helpful if i am able >to get it in a single query. SELECT parent, parent + SUM(orgunit) FROM table GROUP BY parent; PB ----- VenuGopal Papasani wrote: > Hi all, > I Have a table with followin structure where i have orgunit and parent > and value > > > orgunit parent value > > 12 10 x > 15 12 y > 16 12 z > 17 12 p > > Now here 15,16, and 17 are the children of 12 and 12 is > the > child of 10.Now i need a query which gives the sum of all the > children of > 12 and nturn 12 itself . i.e I need the sum(values(15+16+17+12)).Is > there a > query which gives the sum of all these.It will be very helpful if i am > able > to get it in a single query. > > Thanks and regards, > venu. > > ------------------------------------------------------------------------ > > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.1.394 / Virus Database: 268.9.8/380 - Release Date: 6/30/2006 > --------------010905050702070801070705 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit >orgunit                    parent                           value
>12                           10                                  x
>15                            12                                 y
>16                            12                                 z
>17                            12                                 p
>               Now here 15,16, and 17 are the children of 12 and 12 is the
>child of 10.Now i need a query which gives the sum of all the children  of
>12 and nturn 12 itself . i.e I need the sum(values(15+16+17+12)).Is there a
>query which gives the sum of all these.It will be very helpful if i am able
>to get it in a single query.

SELECT parent, parent + SUM(orgunit)
FROM table
GROUP BY parent;

PB

-----


VenuGopal Papasani wrote:
Hi all,
  I Have a table with followin structure where i have orgunit and parent
and value


orgunit                    parent                           value

12                           10                                  x
15                            12                                 y
16                            12                                 z
17                            12                                 p

               Now here 15,16, and 17 are the children of 12 and 12 is the
child of 10.Now i need a query which gives the sum of all the children  of
12 and nturn 12 itself . i.e I need the sum(values(15+16+17+12)).Is there a
query which gives the sum of all these.It will be very helpful if i am able
to get it in a single query.

Thanks and regards,
venu.


No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.394 / Virus Database: 268.9.8/380 - Release Date: 6/30/2006
--------------010905050702070801070705-- --=======AVGMAIL-44A699B851BF======= Content-Type: text/plain; x-avg=cert; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Content-Description: "AVG certification" No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.394 / Virus Database: 268.9.8/380 - Release Date: 6/30/2006 --=======AVGMAIL-44A699B851BF=======--