求高人给个多表联合查询的SQL语句
有表A,B,C,D,E,F,G,他们都有字段"名称","数量","时间",查询满足"时间"在T1到T2区间,"名称"为N1的各个表的"数量"字段的和,即,满足条件的表A的"数量"和,表B的"数量"和,等等。然后将查询结果依次赋值给变量,如:X1=表A的"数量"和,X2=表B的"数量"和。。。我是对各个表做的一个汇总,即当我查询T1到T2时间段,表中就显示如下: 表A 表B 表C 表D 表E 表F 表GN1 "数量"和 "数量"和 "数量"和 "数量"和" 数量"和 "数量"和 "数量"和N2N3N1,N2,N3为以上表的"名称"字段的值。。。。。我是用VB 6.0 编写的代码,然后控件用的是MSFlexGrid头都要大了,在线跪求代码,万分感谢! --------------------编程问答-------------------- 55555555,人呢,快来看看 --------------------编程问答-------------------- 5555555555555555555555555求高人指点 --------------------编程问答--------------------SELECT Name, SUM(Table1) AS TableA, SUM(Table2) AS TableB, SUM(Table3) AS TableC, SUM(Table4) AS TableD, SUM(Table5) AS TableE, SUM(Table6) AS TableF, SUM(Table7) AS TableG
FROM [
SELECT Name,SUM(Number) AS Table1,0 AS Table2,0 AS Table3,0 AS Table4,0 AS Table5,0 AS Table6,0 AS Table7 FROM A_Table WHERE Time BETWEEN #2012-3-1# AND #2012-4-1# GROUP BY Name
UNION
SELECT Name,0 AS Table1,SUM(Number) AS Table2,0 AS Table3,0 AS Table4,0 AS Table5,0 AS Table6,0 AS Table7 FROM B_Table WHERE Time BETWEEN #2012-3-1# AND #2012-4-1# GROUP BY Name
UNION
SELECT Name,0 AS Table1,0 AS Table2,SUM(Number) AS Table3,0 AS Table4,0 AS Table5,0 AS Table6,0 AS Table7 FROM C_Table WHERE Time BETWEEN #2012-3-1# AND #2012-4-1# GROUP BY Name
UNION
SELECT Name,0 AS Table1,0 AS Table2,0 AS Table3,SUM(Number) AS Table4,0 AS Table5,0 AS Table6,0 AS Table7 FROM D_Table WHERE Time BETWEEN #2012-3-1# AND #2012-4-1# GROUP BY Name
UNION
SELECT Name,0 AS Table1,0 AS Table2,0 AS Table3,0 AS Table4,SUM(Number) AS Table5,0 AS Table6,0 AS Table7 FROM E_Table WHERE Time BETWEEN #2012-3-1# AND #2012-4-1# GROUP BY Name
UNION
SELECT Name,0 AS Table1,0 AS Table2,0 AS Table3,0 AS Table4,0 AS Table5,SUM(Number) AS Table6,0 AS Table7 FROM F_Table WHERE Time BETWEEN #2012-3-1# AND #2012-4-1# GROUP BY Name
UNION
SELECT Name,0 AS Table1,0 AS Table2,0 AS Table3,0 AS Table4,0 AS Table5,0 AS Table6,SUM(Number) AS Table7 FROM G_Table WHERE Time BETWEEN #2012-3-1# AND #2012-4-1# GROUP BY Name
]. AS [%$##@_Alias]
GROUP BY Name
ORDER BY Name;
不清楚是不是你要的效果
补充:VB , 数据库(包含打印,安装,报表)