过滤同一数据库中的多个列

时间:2015-12-09 17:08:00

标签: oracle-sqldeveloper

我有两个单独的查询:

SELECT COUNT(*)employees FROM company
WHERE status = 'A' AND salary_rate IS NOT NULL;

SELECT COUNT(*)employees FROM company
WHERE status = 'A' AND current_level IS NOT NULL;

我想在一个查询中显示这两个查询的结果。这可能吗?

1 个答案:

答案 0 :(得分:0)

我认为这就是你要找的东西: How to get multiple counts with one SQL query?

考虑到这一点,你想要这样的东西:

SELECT COUNT(*) AS totalcount, 
   SUM(CASE WHEN salary_rate IS NOT NULL THEN 1 ELSE 0 END) AS cnt1,
   SUM(CASE WHEN current_level IS NOT NULL THEN 1 ELSE 0 END) AS cnt2
FROM company
WHERE status = 'A';

输出将是status ='A'的所有记录的计数,然后计算两个不同的'not null'条件(如cnt1和cnt2)。