Мы можем попробовать использовать оператор Oracle UNPIVOT
здесь:
SELECT
flag AS Col1_name,
COUNT(CASE WHEN val = 'Y' THEN 1 END) AS Y_Count,
COUNT(CASE WHEN val = 'N' THEN 1 END) AS N_Count
FROM yourTable
UNPIVOT
(
val FOR (flag) IN (
flag1 AS 'flag1',
flag2 AS 'flag2',
flag3 AS 'flag3'
)
)
GROUP BY
flag
ORDER BY
flag;
Демо
В другом простом варианте используется ряд объединений:
SELECT
'flag1' AS Col1_name,
COUNT(CASE WHEN flag1 = 'Y' THEN 1 END) AS Y_Count,
COUNT(CASE WHEN flag1 = 'N' THEN 1 END) AS N_Count
FROM yourTable
UNION ALL
SELECT 'flag2', COUNT(CASE WHEN flag2 = 'Y' THEN 1 END),
COUNT(CASE WHEN flag2 = 'N' THEN 1 END)
FROM yourTable
UNION ALL
SELECT 'flag3', COUNT(CASE WHEN flag3 = 'Y' THEN 1 END),
COUNT(CASE WHEN flag3 = 'N' THEN 1 END)
FROM yourTable
ORDER BY 1;
Демо