两个简单的表字段如下:
table1
studentid chinese
1001 56
1002 34
1003 22
table2
studentid chinese
1001 33
1002 66把两边相同的studentID的中文成绩相加studentid chinese
1001 89
1002 100
1003 22如两表中只要一表有的,要体现,如下table1中的1003
table1
studentid chinese
1001 56
1002 34
1003 22
table2
studentid chinese
1001 33
1002 66把两边相同的studentID的中文成绩相加studentid chinese
1001 89
1002 100
1003 22如两表中只要一表有的,要体现,如下table1中的1003
(select t1.studentid ,t1.chinese as a1,t2.chinese as a2 from table1 T1 left join table2 T2 on (T1.studentid =T2.studentid))
(select t1.studentid ,t1.chinese as a1,t2.chinese as a2 from table1 T1 left join table2 T2 on (T1.studentid =T2.studentid))
上面的兄弟写的得到的结果都是:
studentid chinese
1001 89
1002 100
1003
1003的数据没有了
FROM
(SELECT * FROM TABLE1
UNION ALL
SELECT * FROM TABLE2
) A
GROUP BY studentid
------------
ACCESS可以用iif 函數代替isnull
FROM
(SELECT * FROM TABLE1
UNION ALL
SELECT * FROM TABLE2
) A
GROUP BY studentid