Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MaxDB - Everything about MaxDB, formerly known as SAP DB
MySQL++ - Programming with the C++ API to MySQL
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
ODBC - ODBC with the MySQL Connector/ODBC driver
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
need one query

need one query

2006-07-01       - By Peter Brawley

 Back
Reply:     1     2     3  

>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
>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 <meta content="text/html;charset=ISO-8859 (See http://ISO-8859.ora-code.com)-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
&gt;orgunit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parent&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value
<br>
&gt;12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x
<br>
&gt;15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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nbsp;&nbsp; p
<br>
&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; Now here 15,16, and 17 are the children of 12 and 12
is the
<br>
&gt;child of 10.Now i need a query which gives the sum of all the
children&nbsp; of
<br>
&gt;12 and nturn 12 itself . i.e I need the sum(values(15+16+17+12)).Is
there a
<br>
&gt;query which gives the sum of all these.It will be very helpful if i
am able
<br>
&gt;to get it in a single query.
<br>
<br>
SELECT parent, parent + SUM(orgunit)<br>
FROM table <br>
GROUP BY parent;<br>
<br>
PB<br>
<br>
-- --<br>
<br>
<br>
VenuGopal Papasani wrote:
<blockquote
cite="midbcb1c3940607010345r1992ed93hfd6ecba09051c9eb@(protected)"
type="cite">Hi all,
 <br>
&nbsp; I Have a table with followin structure where i have orgunit and
parent
 <br>
and value
 <br>
 <br>
 <br>
orgunit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parent&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value
 <br>
 <br>
12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&n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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p
 <br>
 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; Now here 15,16, and 17 are the children of 12 and 12 is
the
 <br>
child of 10.Now i need a query which gives the sum of all the children&nbsp;
of
 <br>
12 and nturn 12 itself . i.e I need the sum(values(15+16+17+12)).Is
there a
 <br>
query which gives the sum of all these.It will be very helpful if i am
able
 <br>
to get it in a single query.
 <br>
 <br>
Thanks and regards,
 <br>
venu.
 <br>
 <br>
 <pre wrap="">
<hr size="4" width="90%">
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
 </pre>
</blockquote>
</body>
</html>

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



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=mysql@(protected)