id 类型 状态 时间
111 1 0 2009-01-01 12:12:12
111 1 1 2009-01-02 12:12:12
111 1 0 2009-01-03 12:12:12
112 2 0 2009-01-01 12:12:12
112 2 1 2009-01-02 12:12:12
113 1 0 2009-01-03 12:12:12
114 1 1 2009-01-04 12:12:12
115 3 0 2009-01-05 12:12:12
115 3 1 2009-01-06 12:12:12
以id分组,类型相同,时间最新的一条数据
id为111的为例,只要111类型1时间为3号的那条数据
111 1 0 2009-01-01 12:12:12
111 1 1 2009-01-02 12:12:12
111 1 0 2009-01-03 12:12:12
112 2 0 2009-01-01 12:12:12
112 2 1 2009-01-02 12:12:12
113 1 0 2009-01-03 12:12:12
114 1 1 2009-01-04 12:12:12
115 3 0 2009-01-05 12:12:12
115 3 1 2009-01-06 12:12:12
以id分组,类型相同,时间最新的一条数据
id为111的为例,只要111类型1时间为3号的那条数据
select 1 from t where id=t1.id and type=t1.type and ttime>t1.ttime);
from table1 a
where not exists (select 1 from table1 where id=a.id and 类型=a.类型 and 时间>a.时间)