(1)比如
计划的sql是:select 矿种,sum(zd1)... from table1 group by 矿种;
实际的sql是:select 矿种,sum(zd1)... from table2 group by 矿种;
偏差的sql是:select 矿种,sum(zd1)... from table1 t1,table2 t2 where t1.xxx=t2.yyy group by 矿种;
(最好是这样写,不然偏差要在代码里计算就麻烦一些)
(2)首先改造一些,给sql加上类型字段type,区分是那种结果,注意,类型最好定义为数字常量,并且和你表格上的排序大小一致
计划的sql是:select 矿种,sum(zd1).... ,1 type from table1 group by 矿种;
实际的sql是:select 矿种,sum(zd1).... ,2 type from table2 group by 矿种;
偏差的sql是:select 矿种,sum(zd1)... ,3 type from table1 t1,table2 t2 where t1.xxx=t2.yyy group by 矿种;
(3)union上面的结果,并且按照矿种和type排序,注意先后顺序.先排矿种,后排type.
这样出来的结果就是你要的效果了