1

I have two separate queries:

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;

I want to show the results of these two queries in one query. Is this possible?

insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
TrickyDBA
  • 37
  • 1
  • 10

1 Answers1

0

I think this is what you're looking for: How to get multiple counts with one SQL query?

With that in mind, you want something like this:

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';

Output will be the count of all records where status='A' and then counts of the two different 'not null' conditions (as cnt1 and cnt2).

Community
  • 1
  • 1
Stidgeon
  • 2,673
  • 8
  • 20
  • 28