简体   繁体   English

从子查询中选择特定的列

[英]select specific column from subquery

My sample data with the Emp table 我的示例数据与Emp表

Emp

deptno eno
1       1
1       2
1       3
2       1
2       2

output: 输出:

deptno  eno
1        3
2        2

out of this i need to have only one column in final output only 出于这一点,我只需要在最终输出中只有一列

deptno
1
2

I am trying to write 我正在写

select deptno from emp where deptno in (select deptno,max(eno)
from emp
group by deptno);

It is throwing error 它抛出错误

I'm thinking . 我在想 。 . .

select distinct deptno
from emp;

Does that meet your needs? 满足您的需求吗?

Try this 尝试这个

select deptno from emp where deptno in (
    select deptno from emp where eno in (
        select MAX(eno) from emp))
select deptno
from emp 
group by deptno

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM