SELECT TOP 5 Newsid, topic, fstcreate, baseclass FROM dbo.Corpnews c1 WHERE (select count(*) from Corpnews c2 where c2.baseclass=c1.baseclass and c2. Newsid>=c1. Newsid)<=5
错了不要TopSELECT Newsid, topic, fstcreate, baseclass FROM dbo.Corpnews c1 WHERE (select count(*) from Corpnews c2 where c2.baseclass=c1.baseclass and c2. Newsid>=c1. Newsid)<=5
我看不明白,where c2.baseclass=c1.baseclass and c2. Newsid>=c1. Newsid 愿意解释一下吗?多谢!
表示类别和当前记录相同且Newsid大于或等于当前记录的记录。
'查询各类新闻最新5条 select * from Corpnews a where Newsid in (select Top 5 Newsid from Corpnews where baseclass = a.baseclass order by fstcreate desc )
FROM dbo.Corpnews c1
WHERE (select count(*) from Corpnews c2 where c2.baseclass=c1.baseclass and c2. Newsid>=c1. Newsid)<=5
FROM dbo.Corpnews c1
WHERE (select count(*) from Corpnews c2 where c2.baseclass=c1.baseclass and c2. Newsid>=c1. Newsid)<=5
愿意解释一下吗?多谢!
select *
from Corpnews a
where Newsid in (select Top 5 Newsid
from Corpnews
where baseclass = a.baseclass
order by fstcreate desc
)