$SQL= "SELECT sum(total1) as dep_1 FROM (SELECT sum(p1) as total1 FROM table1
union all SELECT sum(p1) as total1 FROM table2
union all SELECT sum(p1) as total1 FROM table3
) as sum1 " or die("Error:" . mysqli_error());
อยาก sum column อื่นด้วยค่ะ แต่ลองเพิ่มแล้ว มันขึ้นแบบนี้ Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in
select * from (
select total1,total1 from
(
SELECT sum(p1), as total1, sum(p11) as total11 FROM table1
),
(SELECT sum(p2) FROM table2) as total2,
(SELECT sum(p3) FROM table3) as total3
)