表1sbh lr date
111 200 2009-01-01
111 300 2008-03-01
111 222 2009-02-01
222 333 2007-03-02
222 322 2007-09-02
333 523 2008-03-03 现在需要统计每个sbh中最后一次LR额sbh lr date
111 222 2009-02-01
222 322 2007-09-02
333 523 2008-03-03表1的数据是用另个select查询生成的,我用以下语句查出来结果是错的,结果显示了所有记录select sbh,lr,max(date) from 表1 group by sbh,lr
盼回复!!!
111 200 2009-01-01
111 300 2008-03-01
111 222 2009-02-01
222 333 2007-03-02
222 322 2007-09-02
333 523 2008-03-03 现在需要统计每个sbh中最后一次LR额sbh lr date
111 222 2009-02-01
222 322 2007-09-02
333 523 2008-03-03表1的数据是用另个select查询生成的,我用以下语句查出来结果是错的,结果显示了所有记录select sbh,lr,max(date) from 表1 group by sbh,lr
盼回复!!!
解决方案 »
- 请教ORACLE SQL查询语句 (子查询条件)
- 新人报道另加问题咨询
- myeclipse 连接oracle 10g错误
- Oracle10g 安装失败 (严重: 参数 PORT 的值 null 无效)
- 在ORACLE存储过程调用存储过程出错了?各位大哥大姐能否帮忙看一下?
- ORA-01031: insufficient privileges 等综合问题等指导
- 请问oracle9i中有没有integer类型?
- 关于视图
- oracle中创建用户.赋予权限时,admin和grant分别代表什么意思啊???
- 初学者!请问在Oracle中能不能在一个字段中存放整型数组?
- pro*c 调用存储过程编译出错
- 求一查询方案的SQL语句具体实现
from(
select sbh,max(date) from 表1 group by sbh
)a1
select *
from 表1 a
where not exists (select sbh from 表1 where sbh=a.sbh and date>a.date);
FROM (
SELECT 表1.* ,MAX(DATE ) over(PARTITION BY sbh) max_date FROM 表1
)
WHERE DATE = max_date
insert into tb_1 values(111,200,to_date('2009-1-1','yyyy-mm-dd'));
insert into tb_1 values(111,200,to_date('2008-3-1','yyyy-mm-dd'));
insert into tb_1 values(111,222,to_date('2009-2-1','yyyy-mm-dd'));
insert into tb_1 values(222,333,to_date('2007-3-2','yyyy-mm-dd'));
insert into tb_1 values(222,322,to_date('2007-9-2','yyyy-mm-dd'));
insert into tb_1 values(333,523,to_date('2008-3-3','yyyy-mm-dd'));
commit;
select * from tb_1 t;select t1.*
from tb_1 t1, (select max(t.dated) date2 from tb_1 t group by t.sbh) t2
where t1.dated = t2.date2