日期:2014-05-17 浏览次数:20435 次
--不是分组后,取第一个吗?
create table t
(
id int,
parentid int,
content varchar(200),
sort int
)
insert into t values (1,1,'123123',0)
insert into t values (2,1,'asdasdasd',0)
insert into t values (3,2,'vrfvfvf',0)
insert into t values (4,2,'43rfrefd',0)
select * from t where id in (select MAX(id) from t group by parentid)
update t set sort=1 where id in (select MAX(id) from t group by parentid)
select * from t