I have 2 tables, t_silm and t_revenue, and I want to sum some both tables with the same condition. This is sample my table:
t_silm
bl - th - tw - total
10 - 2018 - 4 - 100
11 - 2018 - 4 - 200
12 - 2018 - 4 - 300
t_revenue
bl - th - tw - jumlah
10 - 2018 - 4 - 25
11 - 2018 - 4 - 70
12 - 2018 - 4 - 45
I want to get the result:
avg = total / jumlah;
condition = tw =4 and th = 2018;
Please can somebody help me?
$query = "SELECT sum(t_slim.pemakaian_309) as to1, sum(t_revenue.jumlah) as to2, to1/to2 as taverage
from t_slim t1 INNER JOIN t_revenue t2 on t1.tahun=t2.tahun
and t1.triwulan=t2.triwulan WHERE t1.tahun=$tahun and t1.triwulan=$triwulan GROUP BY bulan";
$hasil = mysql_query($query);
$baris = 3;
while ($data = mysql_fetch_array($hasil))
{
$worksheet2->write_string(11, $baris, number_format($data['taverage'],2),$format2);
$baris++;
}
</div>