select ProductCode,sum(num) from a group by ProductCode;

解决方案 »

  1.   

    select ProductCode,InNum-OutNum from
    (select ProductCode,sum(a2) InNum from a group by ProductCode) m,
    (select ProductCode,sum(d3) OutNum from b group by ProductCode) n
    where m.ProductCode=n.ProductCode;
      

  2.   

    a2,d3就是数量了;
    再把时间条件架上,就是你要的SQL语句了。
      

  3.   

    select invalue-nvl(outvalue,0),A.ProductCode from 
    (select sum(nvl(A.数量,0)) invalue,ProductCode,createdate from A where to_char(createdate,'yyyymmddhh')=to_char(sysdate,'yyyymmdd')||'08' group by ProductCode) x,
    (select sum(nvl(B.数量,0)) outvalue,ProductCode,createdate from B where to_char(createdate,'yyyymmddhh')=to_char(sysdate,'yyyymmdd')||'08' group by ProductCode) y
     where a.ProductCode=b.ProductCode(+)
      

  4.   

    一般情况下统计库存都需要一个期初数,如果没有期初数,统计库存需要从出入库表的第一条记录开始统计,才能得出正确的库存量。
    feng2(蜀山风云) 在二楼的Sql已经可以了。只要注意时间条件就行
      

  5.   

    请问时间格式该怎么写?
    我象这样写但是不成功
    select ProductCode,InNum-OutNum from
    (select ProductCode,sum(a2) InNum from a 
    where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss')
    group by ProductCode) m,(select ProductCode,sum(d3) OutNum from b 
    where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss')
    group by ProductCode) nwhere m.ProductCode=n.ProductCode;而时间格式写成和bmws23lk(lk)一样却是通过的?
    但是我用他的时间格式,和我的时间格式统计了一下入库表的数量是不一致的
    我用的是 where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss'),这个也是符合实际的入库数量的
    他用的是 where to_char(createdate,'yyyymmddhh')<to_char(sysdate,'yyyymmdd')||'08' 
    这一句难道是错了吗?
    请问一下这两者有什么不同吗?
      

  6.   

    我用的是where createdate<to_char(to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss'),----这里的createdate是varchar型的?
    这个也是符合实际的入库数量的
    他用的是 where to_char(createdate,'yyyymmddhh')<to_char(sysdate,'yyyymmdd')||'08' ---这里createdate是date型的,这2句表达意思不一样啊
    再说to_date(sysdate+8/24,'yyyy-mm-dd hh:mi:ss'),'yyyy-mm-dd hh:mi:ss')这样写不对吧,截至到今天早上八点,我想你的意思应该是:
    where createdate < trunc(sysdate)+8/24 --createdate 是date类型 
      

  7.   

    时间条件:
     to_char(to_date(createdate,'yyyy-mm-dd hh24:mi:ss'),'yyyymmddhh24')<to_char(sysdate,'yyyymmdd')||'08'