select * 
    商品 = a.name,
    结存 = sum(c.goodnum)
from 
    goodtype a,
    商品表   b,
    (select goodsid,goodnum from HisStore
     union all
     select goodsid,goodsnum from InD) c
where
    a.id = b.goodtype_id and b.id = c.goodsid
group by
    a.name

解决方案 »

  1.   

    select * 
        商品 = a.name,
        结存 = sum(c.goodnum)
    from 
        goodtype a,
        商品表   b,
        (select goodsid,goodnum from HisStore
         union all
         select goodsid,goodsnum from InD) c
    where
        a.id = b.goodtype_id and b.id = c.goodsid
    group by
        a.name
      

  2.   

    我考虑的等式是这样的,可是暂时我还没有想出来如何查询:1,查出所有期初与以后发现的共有的种类T1.
    2,查出所有期初有但后来入没有的种类T2.
    3,查出所有期初无但后来有的种类T3.这样当然结余的种类数为:T1+T2+T3
      

  3.   

    用compute count(goodsid)不就解决了吗?
      

  4.   

    我建了两个表,结构一样,字段名一样,模拟了一下这种情况
    Table1
    T
    1
    2
    3Table2
    T
    3
    4
    5select T1 from 
    (select A.T as T1,B.T as T2 from table1 A full join table2 B on A.T=B.T) A where T1 is not null and T2 is not null
    union
    select T1 as T2 from 
    (select A.T as T1,B.T as T2 from table1 A full join table2 B on A.T=B.T) A where T1 is not null and T2 is  null
    union
    select T2 as T3 from 
    (select A.T as T1,B.T as T2 from table1 A full join table2 B on A.T=B.T) A where T1 is null and T2 is  not null
    我用这样的查询查出了所有可能的值.
    大侠们帮看一下,我这种方法好不好?你们有什么好的方法没有?
      

  5.   

    回复人: ruan_hg(阿阮) ( ) 信誉:100  2005-03-14 12:26:00  得分: 0  
     
     
       用compute count(goodsid)不就解决了吗?
      
     请举个例子,我看了一下帮助,没有看明白.