日期:2014-05-16 浏览次数:20308 次
sql语句:
create table dispatch_result ( dr_id number not null, sheet_id number, check_next varchar(20), check_time date, check_sn char(8), check_comment varchar(255), check_status number, constraint PK_RESULT primary key (dr_id) );
DR_ID SHEET_ID CHECK_NEXT CHECK_TIME CHECK_SN CHECK_COMMENT CHECK_STATUS
---------- ---------- -------------------- ----------- -------- -------------------------------------------- ------------
1 1 10001 2012/8/12 11:11:23 10000 1
2 1 10002 2012/9/15 11:15:24 10001 2
3 2 10001 2012/8/15 9:16:10 10000 1
4 2 10002 2012/9/18 11:16:23 10001 2
查询以SHEET_ID 分组取最大时间记录:
第一种子查询方式:
select * from dispatch_result dr where dr.check_time=( select max(check_time) from dispatch_result where sheet_id=dr.sheet_id)
第二种group by方式:
select t1.* from dispatch_result t1 right join (select sheet_id,max(check_time) ct from dispatch_result group by sheet_id) t2 on t2