本帖最后由 babala2009 于 2013-03-10 11:48:10 编辑

解决方案 »

  1.   

    这数据量,没有索引,sql 怎么写都不会效率高。
      

  2.   

    第一步:首先分析建立索引的字段,提高sql 查询的效率第二部:按照需求写出相应的sql
      

  3.   

    如果真有上亿条的数据
    找dba解决  
    大概 分区什麽的
      

  4.   

    select 仓库编号, sum(数量) as 存入,sum(数量)as 取出,table1.sum(数量)-table2.sum(数量) as 净存 from (selelct 仓库编号,count(数量) as 存入 from table where 存取标记=0 group by 货物类型) as table1,
    (selelct 仓库编号,count(数量)as 取出 from table where 存取标记=1 group by 货物类型) as table2
    where to_date('20010101 00:00','yyyymmdd hh24:mi')<=table1.日期<= to_date('20010131 23:59','yyyymmdd hh24:mi') group by 仓库编号
      

  5.   

    select sum(columnA) 存入,sum(columnB) 取出,sum(columnA)-sum(columnB) 净剩  from tableC group by substr(to_char(日期,'MM'),0,2)
    这样试试
      

  6.   

    A的解决方案:
    select t.仓库编号,nvl(sum(decode(t.存取标记,0,t.数量)),0) a,nvl(sum(decode(t.存取标记,1,t.sl)),0) b,nvl(sum(decode(t.存取标记,0,t.数量)),0)-nvl(sum(decode(t.存取标记,1,t.数量)),0)
     from t where t.日期>to_date('20121230','yyyymmdd') and t.日期<to_date('20130201','yyyymmdd') group by t.仓库编号B的解决方案select a.num,count(decode(sign(a.count1),1,a.count1)),count(decode(sign(a.count1),-1,a.count1)) from
    (
    select t.仓库编号num,nvl(sum(decode(t.存取标记,0,t.数量)),0)-nvl(sum(decode(t.存取标记,1,t.数量)),0) count1 from t  group by t.仓库编号,t.日期
     ) a  
     group by a.num
    希望有点帮助