Re: [問題] 撈出後處理與撈出前處理

看板java作者 (Alien)時間10年前 (2015/10/08 08:32), 編輯推噓3(300)
留言3則, 2人參與, 最新討論串2/2 (看更多)
[方法 3] 有些 DBMS 有 analytic function 可以把 col 扭成 row, 你直接可以取得 col_name, count 的結果 [方法 4] 應該可以動態生成: select sum(col1), sum(col2), sum(col3)... sum(col100) from (select case col1 when '1' then 1 else null, case col2 when '1' then 1 else null, case col3 when '1' then 1 else null .... case col100 when '1' then 1 else null from table -- 再動態生成 where clause 更佳) 或 select col_name, count(*) from ( select 'col1' col_name from table where col1 = '1' UNION ALL select 'col2' col_name from table where col2 = '1' UNION ALL select 'col3' col_name from table where col3 = '1' .... ) group by col_name -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.19.45.239 ※ 文章網址: https://www.ptt.cc/bbs/java/M.1444264323.A.37A.html

10/08 17:55, , 1F
請問這是oracle才有支援嗎
10/08 17:55, 1F

10/08 20:11, , 2F
方法4就一般SQL而已
10/08 20:11, 2F

10/08 23:47, , 3F
要安裝oracle卡在連線無法建立>"< 現在是用mysql
10/08 23:47, 3F
文章代碼(AID): #1M5Rc3Dw (java)
文章代碼(AID): #1M5Rc3Dw (java)