这条语句为什么出现错误?
select * from (select top 10 * from TeachingResource order by newid()) order by id desc "
上面的语句为什么出现错误?
我的意图是:
通过select top 10 * from TeachingResource order by newid())先选择10条随机记录
然后应用
select * from (select top 10 * from TeachingResource order by newid()) order by id desc "根据ID字段进行降序排序,为什么出现错误?
或者
这个语句select top 10 * from TeachingResource order by newid() "能不能就直接实现按ID进行排序,如果能就不使用我的以上语句了,
------解决方案--------------------那是因为你排序字段不明确
select a.* from (select top 10 * from TeachingResource order by newid()) as a order by a.id desc
------解决方案--------------------僅僅是只需要加上一個別名就可以了
select * from (select top 10 * from TeachingResource order by newid()) A order by id desc
A或者任意的名字都可以
------解决方案--------------------SELECT * FROM (SELECT TOP 10 * FROM VideoInfo ORDER BY NEWID()) DERIVEDTBL ORDER BY Id DESC
------解决方案--------------------查询分析器里会自动修正的...
copy回来就可以了~
------解决方案--------------------同意二楼的
------解决方案--------------------查询分析器里面试:)
SELECT * FROM (SELECT TOP 10 * FROM VideoInfo ORDER BY NEWID()) DERIVEDTBL ORDER BY Id DESC
正解:)