JUST DO IT ~

我只想当个程序员

oracle 多条 变 一条 group count(*) 汇集成 1条


oracle
   

insert  table1
select  name ,count(*)
from ...
group by  type


select            ,case type1  ==  value1  , case type2 == value2  , case  type3 = value3  .........这里也要写死的
from table2 , table1

导入到临时表   1:N 然后拼接出一张表 写1次固定代码

还没想到更好的...................????????






其他方式

select     ......
from a
( select  * ,count   from  ...   where   type1  ) t1
( select  * ,count   from  ...   where   type2  ) t2
.
.
.
.

有几种就要写几种.... 但是速度如何呢? 要发动N次的 index count(*)   写2次固定代码



1-1-1-N
可能因为 不是3,6 整天记录都不输出  问题是怎么解决 .



  
select
       a.seatid_      "xwh" ,      
--席位
       b.exchgcode_  "jys"    , --交易所
       b.holderacc_ "khh",        --客户号
       c.password_ "khmm" ,   -- 密码
       count(*)     "num"  ,  
       
case  
            
when  count(*= 0   then   'N'    --不读回报 没有未完成的委托
            else    'Y'                        -- 有未完成的委托 
       end    "qbh"                -- 取回报
      from acc_seat a, acc_holder2seat b , acc_holder c ,dl_entrust  d
     
where a.exchgcode_ =  v_exchgcode
       
and a.seatid_ =  v_seatid
       
and a.exchgcode_ = b.exchgcode_
       
and a.seatid_ = b.seatid_
       
and b.exchgcode_ =c.exchgcode_
       
and b.holderacc_ =c.holderacc_ 
       
and d.exchgcode_ = a.exchgcode_ 
       
and d.seatid_ = a.seatid_ 
       
and d.holderacc_  = b.holderacc_ 
       
and d.entstatus_ not in (3,6)    
     
group by        a.seatid_    ,      --席位
       b.exchgcode_      , --交易所
       b.holderacc_  ,        --客户号
       c.password_ ;  -- 密码 



  select
       a.seatid_      "xwh" ,      
--席位
       b.exchgcode_  "jys"    , --交易所
       b.holderacc_ "khh",        --客户号
       c.password_ "khmm" ,   -- 密码
      nvl( (
       
select  count(*
       
from  dl_entrust  d
       
where  1=1    and d.exchgcode_ = a.exchgcode_ 
       
and d.seatid_ = a.seatid_ 
       
and d.holderacc_  = b.holderacc_ 
       
and d.entstatus_ not in (3,6)    
       ),
0 )     "num"    

  
      
from acc_seat a, acc_holder2seat b , acc_holder c  
     
where a.exchgcode_ =  &v_exchgcode
       
and a.seatid_ =  &v_seatid
       
and a.exchgcode_ = b.exchgcode_
       
and a.seatid_ = b.seatid_
       
and b.exchgcode_ =c.exchgcode_
       
and b.holderacc_ =c.holderacc_ 




posted on 2008-09-08 08:03 小高 阅读(641) 评论(0)  编辑  收藏 所属分类: Oracle


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2008年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

统计

常用链接

留言簿(3)

随笔分类(352)

收藏夹(19)

关注的blog

手册

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜