我有三个表:
我想根据表 3 收集操作和年份对所有结果进行分组。
这里是我想要的一个例子:
tablo1
2017-& gt;2100 (卡克)
tablo2
2017-& gt;600 (borc)
2100 (alacak)-600 (borc) = 1600 (结果)
tablo3
2017-& gt;600 (gider)
1600 (result)-600 (gider) = 1000 (final)
我尝试了这样的代码:
SELECT tablo1.year, (SUM(tablo1.alacak)-SUM(tablo2.borc)-SUM(tablo3.gider)) AS result
FROM
tablo1 JOIN tablo2 ON tablo1.alacak = tablo2.borc
LEFT JOIN giderler ON tablo1.alacak = tablo3.gider
GROUP BY tablo1.year DESC;
但它不起作用。任何帮助将不胜感激。
this是你想要的吗???
select year,
(select sum(alacak) quany
from table1
where table1.year = t3.year)
-
(select sum(borc) quany
from table2
where table2.year = t3.year)
-
(select sum(gider) quany
from table3
where table3.year = t3.year) as result
from table3 t3
group by year;
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(12条)