Hi please go through the following example, Might be it will help you.
如果您正在使用Oracle10g的是這種格式, 如果11克旋轉功能是有
WITH cte(dept_id,salary) AS (SELECT 10,1000 FROM dual
UNION ALL
SELECT 10,1000 FROM dual
UNION ALL
SELECT 10,1000 FROM dual
UNION ALL
SELECT 20,1000 FROM dual
UNION ALL
SELECT 10,2000 FROM dual
UNION ALL
SELECT 10,2000 FROM dual
UNION ALL
SELECT 20,1000 FROM dual
UNION ALL
SELECT 20,2000 FROM dual
UNION ALL
SELECT 20,2000 FROM dual
),
TEMP as(SELECT
dept_id,
count(salary) cnt,salary
FROM
cte
GROUP BY salary, dept_id)
SELECT dept_id,sum(CASE WHEN salary=1000 THEN cnt ELSE 0 END)salary_1000,
sum(CASE WHEN salary=2000 THEN cnt ELSE 0 END) salary_2000 FROM TEMP
GROUP BY dept_id
太好了。你有什麼問題?你使用什麼數據? –
我使用輸入數據更新了問題 – javanoob
也許,「pivot」和/或「dynamic pivot」是您要搜索的術語。 –