There are two tables:

CREATE TABLE [ostatky] ( [id] INTEGER PRIMARY KEY, [d] INTEGER, [m] VARCHAR(20), [y] INTEGER, [point] VARCHAR(80), [predprijatie] VARCHAR(80), [ostatok] CURRENCY); CREATE TABLE [main] ( [id] INTEGER PRIMARY KEY, [d] INTEGER, [m] VARCHAR(20), [y] INTEGER, [point] VARCHAR(80), [predprijatie] VARCHAR(80), [prihod] CURRENCY, [rashod] CURRENCY); 

It is necessary to obtain the result of addition [ostatok] first table and [prihod] second table and subtract [rashod] second table from this. Something like this: SUM(ostatok)+SUM(prihod)-SUM(rashod) .

How to do it?

    2 answers 2

    It seems that you need to join the tables across the enterprise and, possibly, according to the item, if you know what it is, but hardly by id. :-) And you can not connect anything at all:

     select SUM(prihod) - SUM(rashod) + (select sum(ostatok) from ostatky) from main 

      Only it is not clear to me that there with square brackets (in which cases to write, and in which not), but the meaning is as follows:

       select ID, SUM(o.ostatok)+SUM(m.prihod)-SUM(m.rashod) from [ostatky] o left join [main] m on (m.[id] = o.[id]) 
      • brackets are an analogue of double quotes in some SQL dialects (for example, in T-SQL) - Pavel Mayorov