SQL [Oracle]比较多行

时间:2015-03-22 03:27:51

标签: sql oracle

我有一个问题......我有关于员工的信息表,我必须选择部分,更多的员工没有标题,然后是ING标题。我怎样才能做到这一点 ?为什么我不能使用这个我的SQL代码?它说单行子查询返回多行。但我需要比较超过1行。

感谢您的帮助:)

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;

2 个答案:

答案 0 :(得分:3)

您可以使用以下选择

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

答案 1 :(得分:0)

根据问题中的描述,我认为你需要这个:

select count(section_number),title 
from employe 
where title is null or title='ING' 
group by title 
Order by title nulls first

它将为您提供没有职称和员工人数的员工数量=' ING'