Sososo Sososo - 1 year ago 62
SQL Question

Select Query for specific sum (Not Fixed)

I want to subtract Total Amount - Paid Amount amount in first table (tutar) paid amount in second table (odemetutari)

How can I make this for grid view and show tckimlikno,adisoyadi,calculated new amount

SELECT sum(tutar) AS IcraTutari ,tckimlikno
FROM Om_icra_infos
where tckimlikno=tckimlikno
group by tckimlikno

First here find same tutar with same tckimlikno

and second here

SELECT sum(odemetutari)
FROM Om_icraodeme_infos
where tckimlikno=tckimlikno

I want to his for each row show first tutar - second odemetutari = calculatedamount and show this in new selected view

like this:

tckimlikno calculatedamount
1111111111 111,22 ( tutar-odemetutari)

Answer Source
select a.tckimlikno,sum(tutar)-sum(odemetutari) as calculatedamount from
Om_icra_infos a join Om_icraodeme_infos b on a.tckimlikno=b.tckimlikno group by a.tckimlikno;


select t1.tckimlikno,IcraTutari-icraodeme as calculatedamount from
(SELECT  tckimlikno,sum(tutar) AS IcraTutari FROM Om_icra_infos where tckimlikno=tckimlikno  group by  tckimlikno)as t1 join 
(SELECT tckimlikno,sum(odemetutari) as icraodeme FROM Om_icraodeme_infos where tckimlikno=tckimlikno   group by  tckimlikno) as t2
on t1.tckimlikno=t2.tckimlikno groyup by t1.tckimlikno;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download