我有两个表:表名分别是billindex,premoney; 它们里面有数据如下:
在billindex 表(简称为:A):
  billcode   inhoscode  illfullname    ifcheck 
  js000016   ZY000001     某某            F      
在 premoney  表(简称为:B);
   inhoscode  fullname    jktotal      billnumberid 
   ZY000001    某某        250             1
   ZY000001    某某        500             2         
现在要求是用一条SQL 语句实现如下的显示:
  A.billcode   A.inhoscode  A.illfullname   B.jktotal 
   JS000016      ZY000001     某某              750 
  我目前写的是得了两条记录出来,主要是怎么样才能求出表: premoney的jktotal的合计值,并显示结果如上面 .

解决方案 »

  1.   

    select a.billcode,a.inhoscode,a.illfullname,sum(b.jktotal) as jktotal from a,b
    where a.illfullname = b.fullname
      

  2.   

    select a.billcode,a,inhoscode,a.illfullname,b.jkotal from billindex a inner join 
    (select inhoscode,Sum(jktotal) as jktotal from promoney group by inhoscode) b on a.inhoscode=b.inhoscode where ...........
    我没试过,你自己试试看,应该可以的
      

  3.   

    select a.billcode,a.inhosecode,a.illfullname,b.jktotal from a left outer join 
    (select inhoscode,Sum(jktotal) as jktotal from b group by inhoscode) b on a.inhosecode=b.inhoscode 
    这样也可以
      

  4.   

    select a.billcode,a.inhoscode,a.illfullname,sum(b.jktotal) as jktotal from a left join b on a.inhoscode = b.inhoscode
      

  5.   

    select a.billcode,a.inhoscode,a.illfullname,sum(b.jktotal) as totalfrom table3 a,table4 bwhere a.inhoscode =b .inhoscodegroup by a.billcode,a.inhoscode,a.illfullname
      

  6.   

    select distinct a.billcode,a.inhosecode,a.illfullname ,(select Sum(jktotal) as jktotal from b group by inhoscode)   from A INNER join 
    b on a.inhosecode=b.inhoscode 
      

  7.   

    select A.billcode, A.inhoscode, A.illfullname,sum(B.jktotal)
    from billindex A,premoney B
    where A.inhoscode =B .inhoscode
    group by A.billcode,A.inhoscode,A.illfullname