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 小高 閱讀(685) 評論(0)  編輯  收藏 所屬分類: Oracle

          導航

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

          統計

          常用鏈接

          留言簿(3)

          隨筆分類(352)

          收藏夾(19)

          關注的blog

          手冊

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 高安市| 化州市| 青岛市| 扎鲁特旗| 建德市| 交城县| 鹤山市| 林甸县| 曲阜市| 根河市| 松潘县| 庆阳市| 若尔盖县| 勐海县| 凤翔县| 台南市| 泽普县| 富源县| 西昌市| 武鸣县| 东阳市| 芜湖市| 乐都县| 湛江市| 句容市| 黄大仙区| 蓬溪县| 桐庐县| 永平县| 平和县| 咸阳市| 盘锦市| 赤水市| 耿马| 靖安县| 云浮市| 儋州市| 韩城市| 芒康县| 观塘区| 太仆寺旗|