查询求解
create table t_test
(
t_num varchar(30),
t_time varchar(30),
t_other varchar(30)
)
insert into t_test values('1001','20120701','aaaaaaaaaaaa');
insert into t_test values('1001','20120707','bbbbbbbbbbbb');
insert into t_test values('1002','20120702','cccccccccccc');
insert into t_test values('1003','20120706','dddddddddddd');
insert into t_test values('1003','20120709','eeeeeeeeeeee');
如何查询出1001,1002,1003这三个账号的时间最新的信息
------解决方案--------------------SQL code
select * from t_test t
where not exists(select 1 from t_test where t_time>t.t_time and t_num=t.t_num)
------解决方案--------------------
SQL code
select
*
from
t_test t
where
not exists(select 1 from t_test where t_time>t.t_time and t_num=t.t_num)
--
或者
select
*
from
t_test t
where
t_time=(select max(t_time) from t_test where t_num=t.t_num)