|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi, im a total newb at oracle and SQL, and i am lost. my first question is (im sure more will come)
i want to run 2 queries that look something like this: select sum( columnName ) from tableName where bla bla bla; and i want to add those 2 sums together, and i want to do it all in one solitary query. can anybody please help me? -ben |
|
#2
|
||||
|
||||
|
I just ran a little test whose output should help you out:
Code:
mysql> select * from math; +------------+------+------+ | id | num | num2 | +------------+------+------+ | 0000000001 | 5 | 12 | | 0000000002 | 5 | 3 | | 0000000003 | 5 | 12 | | 0000000004 | 5 | 3 | | 0000000005 | 5 | 12 | | 0000000006 | 7 | 3 | | 0000000007 | 7 | 12 | | 0000000008 | 7 | 3 | | 0000000009 | 7 | 12 | | 0000000010 | 7 | 3 | +------------+------+------+ 10 rows in set (0.00 sec) mysql> select sum(num) from math; +----------+ | sum(num) | +----------+ | 60 | +----------+ 1 row in set (0.00 sec) mysql> select sum(num2) from math; +-----------+ | sum(num2) | +-----------+ | 75 | +-----------+ 1 row in set (0.00 sec) mysql> select sum(num) + sum(num2) from math; +----------------------+ | sum(num) + sum(num2) | +----------------------+ | 135 | +----------------------+ 1 row in set (0.00 sec)
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > adding results of 2 queries |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|