两个表分别汇总选其中的某些字段在dataGrid1中如何显示?
表1:
A B C D
1 aa 0.1 10
2 bb 0.2 3
2 bb 0.2 5
3 c 11 6
表2:
A B1 D1 C2
2 a 6 12.3
2 b 10 5
1 f 21 8
4 c 6 0.3
表1.A和表2.A相同字段,现要将中重复的行
表1用 "select A ,sum(D) from 表1 group by A ";
表2用 "select A ,sum(D1) from 表2 group by A ";
就是表1中各行以字段A分组统计,相加。
表2中各行以字段A分组统计,相加。
在dataGrid1中显示如下
A B D D1
1 aa sum(D)汇总后的值 sum(D1)汇总后的值
2 bb sum(D)汇总后的值 sum(D1)汇总后的值
3 c .... .....
4 .... .....
就是两个表分别汇总后,选其中的某些字段在dataGrid1中显示,应如何做?
------解决方案--------------------select A,sum(d),sum(d1) from (select A ,sum(D) as d,0 as d1 from 表1 group by A " union select A ,0 as d,sum(D1) as d1 from 表2 group by A) group by A
------解决方案--------------------select 表1.A, 表1.D,表2.D1 FROM
( "select A ,sum(D) AS D from 表1 group by A " ) 表1
LEFT JOIN ( "select A ,sum(D1) AS D1 from 表2 group by A ") 表2
on 表1.A = 表2.A
------解决方案--------------------不会,帮顶