我有下表
ID TYPE
--- ----
1 P
1 W
2 P
3 W
4 W
4 X
5 P
6 null
我需要创建一个新表,如下所示
ID Count of Type Code
-- -------------- -------
1 2 null
2 1 P
3 1 W
4 2 null
5 1 P
6 0 null
1st col ---> ID
2nd col ---> count of "type" for an ID
3rd col ---> if count(type) = 1 then TYPE
else null
请帮助我编写 ORACLE SQL 查询