ORACLE 统计正负个数sql

来源:互联网 发布:淘宝双12活动力度 编辑:程序博客网 时间:2024/04/20 10:59

select ss.*,
       sum(ss.aa) over (partition by ss.zsid order by ss.zsid) as fu,
       sum(ss.bb) over (partition by ss.zsid order by ss.zsid) as zheng
from
(
select m.zsid,
       sum(n.f0004_028n) over(partition by m.zsid) n011,
       sum(n.f0004_029n) over(partition by m.zsid) n012,
       sum(n.f0004_030n) over(partition by m.zsid) n013,
       sum(n.f0004_031n) over(partition by m.zsid) n014,
       sum(n.f0004_032n) over(partition by m.zsid) n015,
       sum(n.f0004_033n) over(partition by m.zsid) n021,
       sum(n.f0004_034n) over(partition by m.zsid) n022,
       sum(n.f0004_035n) over(partition by m.zsid) n023,
       n.f0004_017n,
       (case when n.f0004_017n>0 then 1  when n.f0004_017n<=0 then 0 end)  aa,
       (case when n.f0004_017n<=0 then 1  when n.f0004_017n>0 then 0 end)  bb
  from (select a.f0055_001n zsid,
               a.f0055_004v zsbm,
               b.f0056_003v code,
               b.f0056_004v zsjycs, --指数交易场所
               b.f0056_005v zszqlb, --指数证券类别
               c.f0005_005v codezqlb, --成份股证券类别
               c.f0005_007v codejycs --成份股交易场所
          from tb_index_0055@p1 a, tb_index_0056@p1 b, tb_public_0005@p1 c
         where b.f0056_001d = to_date('20100106', 'yyyymmdd') --交易日
           and b.f0056_003v = c.f0005_001v
           and a.f0055_001n = b.f0056_002n) m,
       tb_ori_0004 n
 where m.code = n.f0004_005v
   and m.codezqlb = n.f0004_004v
   and m.codejycs = n.f0004_003v
   and n.f0004_001d = to_date('20100106', 'yyyymmdd')
   and n.f0004_002v = '1102' --当前时间点
 order by m.zsid asc, m.code asc
 )ss
 where ss.zsid=1
 

 

原创粉丝点击