日期:2014-05-17 浏览次数:20861 次
create table t
(
id int,
userid int,
subject varchar(20)
)
insert into t
select 1,1,'标题1' union all
select 2,1,'标题2' union all
select 3,2,'标题3' union all
select 4,3,'标题4' union all
select 5,4,'标题5' union all
select 6,2,'标题6' union all
select 7,3,'标题7' union all
select 8,7,'标题8'
go
with cte as
(
select top 10 max(t1.id)id,t1.userid
from
t t1 inner join t t2 on t1.userid=t2.userid
group by t1.userid
)
select id,userid
from
cte
order by id desc
select * from
(
select max(t.id) as [id] from t group by t.userid
) order by [id] desc
create table t
(
id int,
userid int,
subject varchar(20)
)
insert into t
select 1,1,'标题1' union all
select 2,1,'标题2' union all
select 3,2,'标题3' union all
select 4,3,'标题4' union all
select 5,4,'标题5' union all
select 6,2,'标题6' union all
select 7,3,'标题7' union all
select 8,7,'标题8'
go
select top 10 * from
(
select max(t.id) as [id] from t group by t.userid
)t
order by [id] desc