Reputation: 107
I have a problem... I have table with informations about employees and I have to select sections, where is more employees without title then with ING title. How can i do that ? Why cant I use this mine SQL code ? It says single-row subquery returns more than one row. But i need to compare more than 1 row.
Thank for help :)
select section_number from employe where
(select count(section_number) from employe where title='ING' group by section_number)
>
(select count(section_number) from employe where title IS NULL group by section_number)
group by section_number;
Upvotes: 0
Views: 538
Reputation: 5072
You can use the below select
With ing_title as (select count(1) sec_ing,
section_number from employe where title='ING'
group by section_number),
null_title as ( select count(1) sec_null,
section_number from employe where title is null group by section_number)
select ing_title.section_number
from ing_title,null_title
where ing_title.sec_ing > null_title.sec_null
and ing_title.section_number=null_title.section_number
Upvotes: 3
Reputation: 7880
according to descriptions in the question, I think you need this:
select count(section_number),title
from employe
where title is null or title='ING'
group by title
Order by title nulls first
it will give you number of employees with no title and number of employees with title='ING'
Upvotes: 0