日期:2014-05-18  浏览次数:20585 次

急求一sql句子!
例如表aa:
aa         bb           cc
1             255         20061212
1             15           20061210
2             33           20060612
2               11           20060101
按cc用DESC排序了,
如我想删除where   aa= '2 'or   其他中处的最近时间资料.
结果表aa:
aa         bb           cc
1             255         20061212
2             33           20060612

谢谢!


------解决方案--------------------
create table tt
(
aa int ,
bb int ,
cc varchar(08)
)
insert into tt
select 1, 255 , '20061212 ' union
select 1, 15 , '20061210 ' union
select 2, 33 , '20060612 ' union
select 2, 11 , '20060101 '

select a.*
from tt a
where not exists
(select 1 from tt where aa = a.aa and cc > a.cc)
------解决方案--------------------
delete from t where aa=2 and cc in (select max (cc) from t where aa =2)
select * from t
------解决方案--------------------
http://community.csdn.net/Expert/topic/5275/5275251.xml?temp=.1500818

帮我看看哈.