create table t_temp(
id number,
num1 number,
num2 number
)insert into t_temp values('1','2','2');
insert into t_temp values('2','2','3');
insert into t_temp values('3','2','');
select * from t_temp t;
ID NUM1 NUM2
---------- ---------- ----------
1 2 2
2 2 3
3 2
我要取出以num1为分组,id最大,num2不为空的值
也就是num2为3的值
id number,
num1 number,
num2 number
)insert into t_temp values('1','2','2');
insert into t_temp values('2','2','3');
insert into t_temp values('3','2','');
select * from t_temp t;
ID NUM1 NUM2
---------- ---------- ----------
1 2 2
2 2 3
3 2
我要取出以num1为分组,id最大,num2不为空的值
也就是num2为3的值
解决方案 »
- 问个ORACL问题。
- Oracle存储过程,希望有高手解答下
- 高手帮忙,关于Insert操作
- 求一个sql语句
- 请问ORACLE中,怎样获得两个时间相差的秒数?
- 如何记录用户登录使用的账号、登录是否成功、登录时间
- 为什么我的初始化参数修改后不起作用???
- 在windows nt环境下安装完oracle数据库,运行net8 easy config的时候出现错误,错误信息是……
- 批量插入数据
- 我只好结了贴子再问这个问题,都快搞疯了
- 做数据文件恢复时出现ORA-01179: 文件 不存在,怎么解决?
- oracle last_value()over() 和first_value()over() 怎么使用
(select row_number() over(partition by num1 order by id desc) rn,t_temp.*
from t_temp
where num2 is not null) t
where rn=1;
SQL> edit
已写入 file afiedt.buf 1 with tt as(select '1' id, '2' num1, '2' num2 from dual
2 union all select '2', '2', '3' from dual
3 union all select '3', '2', '' from dual)
4 select * from tt a where
5 not exists(select 1 from tt b where b.id > a.id and b.num1 = a.num1 and b.n
um2 is not null) and
6* a.num2 is not null
SQL> /I N N
- - -
2 2 3SQL>