看板 java 關於我們 聯絡資訊
[方法 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
qazsd: 請問這是oracle才有支援嗎 10/08 17:55
BlueBird5566: 方法4就一般SQL而已 10/08 20:11
qazsd: 要安裝oracle卡在連線無法建立>"< 現在是用mysql 10/08 23:47