select top 5 * from table where id not in (select top 6 id from #temp)
select top 3 NewsId , CategoryId , Title , Content , SpecialID from news where newsid not in ( select top 1 NewsId from news where TopNews = 1 and GoodNews = 1 and pic = 1 ORDER by newsid desc ) and CategoryID = 1 and TopNews = 1 and GoodNews = 1 ORDER by newsid desc 这条语句有什么错误么? 为什么 newsid not in ( select top 1 NewsId from news where TopNews = 1 and GoodNews = 1 and pic = 1 ORDER by newsid desc ) 里面不管是top x都是一样的结果。
--Use tmp tableSET NOCOUNT ON create table #tmp( SeqNo int identity, NewsId varchar(5),--change your type CategoryId varchar(5), Title varchar(200), Content varchar(1000), SpecialID varchar(5))goinsert into #tmp(NewsId , CategoryId , Title , Content , SpecialID) select NewsId , CategoryId , Title , Content , SpecialID from news where TopNews = 1 and GoodNews = 1 ORDER by newsid desc goselect NewsId , CategoryId , Title , Content , SpecialID from #tmp where SeqNo between 7 and 12 goDROP table #tmp goSET NOCOUNTOFF
to boyyao(迷失在网络) : 这条语句有什么错误么? 为什么 newsid not in ( select top 1 NewsId from news where TopNews = 1 and GoodNews = 1 and pic = 1 ORDER by newsid desc ) 里面不管是top x都是一样的结果。是不是条件TopNews = 1 and GoodNews = 1 and pic = 1 决定了只有一条结果?
from news
where
newsid not in
(
select top 1 NewsId from news where TopNews = 1 and GoodNews = 1 and pic = 1 ORDER by newsid desc
)
and
CategoryID = 1 and TopNews = 1 and GoodNews = 1
ORDER by newsid desc
这条语句有什么错误么?
为什么
newsid not in
(
select top 1 NewsId from news where TopNews = 1 and GoodNews = 1 and pic = 1 ORDER by newsid desc
) 里面不管是top x都是一样的结果。
create table #tmp(
SeqNo int identity,
NewsId varchar(5),--change your type
CategoryId varchar(5),
Title varchar(200),
Content varchar(1000),
SpecialID varchar(5))goinsert into #tmp(NewsId , CategoryId , Title , Content , SpecialID)
select NewsId , CategoryId , Title , Content , SpecialID from news where TopNews = 1 and GoodNews = 1 ORDER by newsid desc
goselect NewsId , CategoryId , Title , Content , SpecialID from #tmp
where SeqNo between 7 and 12
goDROP table #tmp
goSET NOCOUNTOFF
这条语句有什么错误么?
为什么
newsid not in
(
select top 1 NewsId from news where TopNews = 1 and GoodNews = 1 and pic = 1 ORDER by newsid desc
) 里面不管是top x都是一样的结果。是不是条件TopNews = 1 and GoodNews = 1 and pic = 1 决定了只有一条结果?