SQL query from 2 tables before do another operation
SQL (firstly, query from 2 tables before do another operation)
SELECT fields & operation FROM (SQL query for table1) as alias table1 name INNER JOIN (SQL query for table2) as alias table2 name on alias table1 name.field=alias table2 name.field GROUP BY alias table1 name. field
for example
SELECT t1.P60_GIndusE, (SUM(t2.LG)-SUM(t1.LG)) as LG FROM (SELECT P60_GIndusE, SUM(LG) as LG FROM table_6001 WHERE ContSize = ‘Test’ GROUP BY P60_GIndusE order by sum(Principal) DESC) as t1 INNER JOIN (SELECT P60_GIndusE, SUM(LG) as LG FROM table_6002 WHERE ContSize = ‘Test’ GROUP BY P60_GIndusE order by sum(Principal) DESC) as t2 on t1.P60_GIndusE=t2.P60_GIndusE GROUP BY t1.P60_GIndusE