use aaaa
go
drop table person
create table person
(
id int identity(1,1) not null,
pid varchar(18) not null,
md varchar(11) not null,
age int
)
go
declare @pid varchar(15)
declare @age int
declare @mb varchar(11)
declare @count int
set @count=0
while(@count<10000)
begin
--select @pid=substring(cast(rand() as varchar(20)),3,6)+substring(cast(rand() as varchar(20)),3,6)+substring(cast(rand() as varchar(20)),3,6)
select @pid=substring(cast(rand() as varchar(20)),3,6)
select @mb=substring(cast(rand()as varchar(20)),3,6)+substring(cast(rand() as varchar(20)),3,5)
select @age=cast(rand()*100 as int)
insert into person values(@pid,@mb,@age)
set @[email protected]+1
end
declare @bd dateTime
declare @ed dateTime
set @bd=getDate()
select top 1 * from person order by age desc
set @ed=getdate()
select datediff(millisecond,@bd,@ed)
if exists(select * from sysindexes where name='ix_age')
drop index person.ix_age
go
create nonclustered index ix_age
on person(age)
go
select * from person where id=(select max(index=ix_age) from person)
------解决方案--------------------
最好给出完整的表结构,测试数据,计算方法和正确结果.
发帖注意事项
http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281