关于SQL
数据如下
time cs_cmid CS_Follow
2011-11-27 1 1,2,3,4
2011-12-06 2 1,2,3
2011-12-05 2 1,3,4
2011-12-03 2 1,7,9
2011-12-03 3 1,7,9
2011-11-30 3 2,3
根据cs_cmid分组,在同一组的取time最大一条数据,最后结果应为
2011-11-27 1 1,2,3,4
2011-12-06 2 1,2,3
2011-12-03 3 1,7,9
没想通要怎么弄,求高手指点
------解决方案--------------------select *
from tbname k
where not exists(select * from tbname where
time =k.time and k.cs_cmid<cs_cmid
)
------解决方案--------------------select max(time) as time,cs_cmid from tbname group by cs_cmid
然后再去join查一下CS_Follow值就行了
------解决方案--------------------SQL code
select * from tbname k
where exists(select 1 from tbname where
cs_cmid=k.cs_cmid and k.time>time
)