all,请帮助此查询。我需要根据用户和部门的每行中缺少值的数量和零行的百分比查询几个表格中的信息。员工需要在系统中注册此信息。基本上,我们需要报告员工已经为系统提供的缺失价值。例如;查询结果
COL_1 |COL_2 |COL_3 |COL_4 |count % d%
----------------------------- ------------
user1 | dept1 | NULL | X |1 50
user2 | dept2 | NULL | NULL |2 100
user3 | dept1 | X | X |0 0
user4 | dept2 | NULL | X |1 50
感谢您是否可以帮助我进行此查询。谢谢。
SELECT t.*,
NVL2( COL_3, 0, 1 ) + NVL2( COL_4, 0, 1 ) AS "Count %",
NVL2( COL_3, 0, 50 ) + NVL2( COL_4, 0, 50 ) AS "d%"
FROM table_name t
SELECT a.col_1
, a.col_2
, COUNT (*) "count"
, SUM (CASE WHEN a.col_3 IS NULL THEN 1 ELSE 0 END) / COUNT (*) * 100 "d%"
FROM table1 a
GROUP BY col_1, col_2;