34,576
社区成员
发帖
与我相关
我的任务
分享
'可以运行啊...'
if object_id('tb')is not null drop table tb
if object_id('test')is not null drop view test
go
create table tb
(
id int,
date datetime
)
go
alter table tb add default getdate() for date
go
insert into tb(id) select 1
union all select 3
union all select 2
union all select 4
go
create view test
as
select id,date=max(date) from tb
group by id;
go
select * from test
/*
id date
---------------------------------
1 2010-04-26 12:42:53.827
2 2010-04-26 12:42:53.827
3 2010-04-26 12:42:53.827
4 2010-04-26 12:42:53.827
*/