为什么不把baseclass作为一个变量来处理,用循环,是不是比这个代码要少好多

解决方案 »

  1.   

    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
      

  2.   

    错了不要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
      

  3.   

    我看不明白,where c2.baseclass=c1.baseclass and c2. Newsid>=c1. Newsid
    愿意解释一下吗?多谢!
      

  4.   

    表示类别和当前记录相同且Newsid大于或等于当前记录的记录。
      

  5.   

    '查询各类新闻最新5条
    select *
    from Corpnews a
    where Newsid in (select Top 5 Newsid
                       from Corpnews
                      where baseclass = a.baseclass 
                   order by fstcreate desc
                     )