两个简单的表字段如下:
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

解决方案 »

  1.   

    Select studentid ,a1+a2 from
    (select t1.studentid ,t1.chinese as a1,t2.chinese as a2 from table1 T1 left join table2 T2 on (T1.studentid =T2.studentid))
      

  2.   

    不行,1003的数量22出不来,我用access
      

  3.   

    Select studentid ,isnull(a1,0)+isnull(a2,0) from
    (select t1.studentid ,t1.chinese as a1,t2.chinese as a2 from table1 T1 left join table2 T2 on (T1.studentid =T2.studentid))
      

  4.   

    1003 出不来吗,不可能吧,用了left join应该可以的呀。
      

  5.   

    real_name(*真名) :access不能用isnull函数
    上面的兄弟写的得到的结果都是:
    studentid  chinese
     1001        89
     1002        100
     1003        
    1003的数据没有了
      

  6.   

    SELECT studentid,SUM(chinese) AS chinese
    FROM
    (SELECT * FROM TABLE1
    UNION ALL
     SELECT * FROM TABLE2
    ) A
    GROUP BY studentid 
    ------------
    ACCESS可以用iif 函數代替isnull
      

  7.   

    SELECT studentid,SUM(ISNULL(chinese)) AS ChineseSum
    FROM
    (SELECT * FROM TABLE1
    UNION ALL
     SELECT * FROM TABLE2
    ) A
    GROUP BY studentid