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
          .
          .
          .
          .

          有幾種就要寫幾種.... 但是速度如何呢? 要發(fā)動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 小高 閱讀(685) 評論(0)  編輯  收藏 所屬分類: Oracle

          導航

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

          統(tǒng)計

          常用鏈接

          留言簿(3)

          隨筆分類(352)

          收藏夾(19)

          關注的blog

          手冊

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 永善县| 湟中县| 绥滨县| 灵川县| 息烽县| 甘泉县| 射阳县| 普兰县| 太和县| 开封县| 扶绥县| 化隆| 榆社县| 南和县| 汶川县| 凤翔县| 宜川县| 荔波县| 两当县| 贵定县| 宁乡县| 洞口县| 泰来县| 睢宁县| 沧州市| 兴文县| 上高县| 南陵县| 富宁县| 邵阳市| 巴楚县| 韶关市| 肃北| 桐城市| 秭归县| 永平县| 农安县| 微山县| 通许县| 镇江市| 深圳市|