Re: [問題] 撈出後處理與撈出前處理
[方法 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
10/08 17:55, 1F
推
10/08 20:11, , 2F
10/08 20:11, 2F
推
10/08 23:47, , 3F
10/08 23:47, 3F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
問題
1
4