两表联合求和查询
access两个表
table1.a, table2.d 数据类型为货币
table1.b,table2.b 数据类型为数字
table1.c,table2.e 数据类型为时间
table1
a b c
table2
d b e
以table1.b=table2.b为条件对表table1,table2进行联合查询,将table1.a, table2.d 的求和结果然按table1.c,table2.e年月分组返回
例如:
sum(table1.a) sum(table2.d) 2006年11月
sum(table1.a) sum(table2.d) 2006年10月
.
.
.
.
sum(table1.a) sum(table2.d) 2006年1月
问题点数:20、回复次数:10Top
1 楼speed4(速度4)回复于 2006-12-04 09:52:52 得分 0
怎么没人顶Top
2 楼shiliangdong(Stou)回复于 2006-12-04 17:35:36 得分 20
select a,c,sum(b) as b from(
select a,c,sum(b) as b from table1 group by a,c
union all
select d as a,e as c,sum(b) as b from table2 group by d,e) as tb3
group by a,cTop
3 楼speed4(速度4)回复于 2006-12-05 10:01:33 得分 0
楼上的理解错了
我的意思是
如果我分开查询应该是:
select sum(a) as a, year(c) as c1, month(c) as c2 from table1 where b="&request("b")&" group by year(c),month(c)
得出结果:
a c1 c2
. . .
. . .
. . .
select sum(d) as d, year(e) as e1, month(e) as e2 from table2 where b="&request("b")&" group by year(e),month(e)
得出结果:
d e1 e2
. . .
. . .
. . .
现在我想要把得到的两个结果整合到一起
a d c1 c2
. . . .
. . . .
. . . .
应该怎么做?Top
4 楼speed4(速度4)回复于 2006-12-05 11:08:12 得分 0
我顶!Top
5 楼speed4(速度4)回复于 2006-12-05 11:08:22 得分 0
我再顶Top
6 楼hreoghost(Challenge oneself,break through limit!)回复于 2006-12-05 11:25:15 得分 0
用视图Top
7 楼snowwolf9999()回复于 2006-12-05 11:38:27 得分 0
union allTop
8 楼speed4(速度4)回复于 2006-12-05 11:45:52 得分 0
能不能具体些Top
9 楼speed4(速度4)回复于 2006-12-05 13:50:09 得分 0
顶Top
10 楼speed4(速度4)回复于 2006-12-06 14:58:01 得分 0
顶Top




