English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

If I have like Select SUM(amount) AS TotalA from tableA
and Select SUM(amountB) AS TotalB from tableB,
is there a way i can create a query that adds or subtract these two values even if the tables are not linked by a relationship??

Any help is greatly appreciated..

P.S I am trying to find a way to get sort of a bank balance, like all my credits and debit are stored in different tables and i want to create a query that gets the balance.

2007-05-01 22:10:35 · 3 answers · asked by Phugz 1 in Computers & Internet Programming & Design

The problem with the first one is that the amount or total is just mathematically incorrect, the numbers are way too big, like in the millions, as much as i wish that's my balance, it's not, : )

The second answer gives me the right amount but it retrieves multiple rows, like the number of rows in the first table times by of added with the the number of rows in the second table.

I really appreciate the help, it's really close..

2007-05-02 16:12:10 · update #1

3 answers

select ( select sum(amounta) from Table1 )+ ( select sum (amountb) from Table2 )
as total from dual

Hope this works for u...

2007-05-01 23:55:32 · answer #1 · answered by Appu 1 · 0 0

Select SUM(tableA.amount) + SUM(tableB.amountB) as Balance
from tableA, tableB

2007-05-01 23:27:05 · answer #2 · answered by AnalProgrammer 7 · 0 0

declare @ValueA float
decalre @ValueB float
declare @MySum float
declare @MyDifference float
set @ValueA = (select SUM(amount) from tableA)
set @ValueB = (select SUM(amountB) from tableB)
set @MySum = @ValueA+@ValueB
set @MyDifference = @ValueA-@ValueB
select @MySum
select @MyDifference

2007-05-03 03:43:33 · answer #3 · answered by Robert S 2 · 0 0

fedest.com, questions and answers