0

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;
1
  • is your group by column correct ??? Commented Mar 22, 2015 at 3:58

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you :) I didnt even know that i can define 2 new tables from my table and then select that... :)
0

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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.