两张表如下:
t1{f1[char],f2[int]}  t2{f3[char],f1[char]}
   A        6            X        A
   B        7            Y        B
   A        10           Z        C结果:
    X   16
    Y   7
    Z   0要求写出SQL语句得到如上结果。回答问题正确的人可以到这儿回帖领分:)
http://topic.csdn.net/u/20080304/12/bdcd299f-9d33-4b50-b461-3d04aa4e2f17.html由于时间紧迫,这儿人比较多,所以到这儿发帖,望斑竹高抬贵手~~~~~

解决方案 »

  1.   

    SELECT t2.f3,t1.f2 FROM t1, t2 WHERE t1.f1=t2.f1
      

  2.   

    不知是太简单了还是你没说清楚:select t2.f3,
    (select sum(f2) from t1 where t1.f1=t2.f1) as f5
    from t2
      

  3.   

    把楼上的优化了一下
    select t2.f3, 
    (select IsNull(sum(f2),0) from t1 where t1.f1=t2.f1) as f5 
    from t2
      

  4.   

    select t2.f3,
    isnull((select sum(f2) from t1 where t1.f1=t2.f4),0) as f5
    from t2
      

  5.   

    OK,谢谢大家了,结贴了,echeng192到另一个贴去回复 :)