请教一个关于SQL嵌套子查询的问题?
createtablePaiHang--排行([ID]intidentity(1,1)primarykey,--自动增长列(主键)[Name]varchar(15)not...
create table PaiHang--排行
(
[ID] int identity(1,1) primary key,--自动增长列(主键)
[Name] varchar(15) not null,--姓名
KaiFa int not null,--开发
JiXiao int not null,--绩效
Type int default 0,--模块标识(默认为0)
Createtime datetime default getdate()--添加时间
)
在上面这个表里做查询,
找出最新添加的5条数据,并按开发或者绩效分别作降序排列,
请教老师后的正确语句是:
select * from paihang where [id] in (select top 5 [id] from paihang where type=0 order by [id] desc) order by kaifa desc
贴出来让遇到同样问题的朋友借鉴!!! 展开
(
[ID] int identity(1,1) primary key,--自动增长列(主键)
[Name] varchar(15) not null,--姓名
KaiFa int not null,--开发
JiXiao int not null,--绩效
Type int default 0,--模块标识(默认为0)
Createtime datetime default getdate()--添加时间
)
在上面这个表里做查询,
找出最新添加的5条数据,并按开发或者绩效分别作降序排列,
请教老师后的正确语句是:
select * from paihang where [id] in (select top 5 [id] from paihang where type=0 order by [id] desc) order by kaifa desc
贴出来让遇到同样问题的朋友借鉴!!! 展开
1个回答
展开全部
select top 5 * from (select * from paihang order by createtime desc) order by kaifa desc;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询