表如下:
SID STime
1 2009-1-1
2 2009-1-1
3 2009-1-1
4 2009-1-1
1 2009-1-2
2 2009-1-2
3 2009-1-2
4 2009-1-2
1 2009-1-3
2 2009-1-3
3 2009-1-3
4 2009-1-3
1 2009-1-4
2 2009-1-4
3 2009-1-4
4 2009-1-4我想查询日期最新的SID数据用了Group by 都不行!请教各位大侠了。
SID STime
1 2009-1-1
2 2009-1-1
3 2009-1-1
4 2009-1-1
1 2009-1-2
2 2009-1-2
3 2009-1-2
4 2009-1-2
1 2009-1-3
2 2009-1-3
3 2009-1-3
4 2009-1-3
1 2009-1-4
2 2009-1-4
3 2009-1-4
4 2009-1-4我想查询日期最新的SID数据用了Group by 都不行!请教各位大侠了。
select distinct sid
from t
where sTime = (select max(Stime) from t)
--TRY
select a.* from tb a where not exists(select 1 from tb where SID = a.SID and STIME > a.STIME)
from table
order by stime desc
select sid
from yourtable
where sTime >= ALL(select Stime from yourtable)
select sid
from t
where sTime = (select max(Stime) from t)
得出结果!有没有不用查询两次的?呵呵