表:T 
字段:id   自动递增, 
          field1   数字, 
          ..... 
select   *   from   ( 
select   *,(select   count(*)   from   T   as   t2   where   t2.field1=t1.field1   and   t2.id <=t1.id)   as   aaa   from   T   as   t1)   as   t3 
where   aaa <=2

t2.field1=t1.field1是分组的条件,可自由添加

参考地址:

http://topic.csdn.net/t/20040819/17/3291042.html

 

 

取出数据中每个分类前5条

 

select ID,title,D_Picture,addtime,newstypeid,jj,content
 FROM news ns
 where ID in (select top 5 ID from news where newstypeid = ns.newstypeid and isActive='1' order by addtime desc)  

 

相关文章:

  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-01-01
  • 2022-01-01
  • 2021-11-02
猜你喜欢
  • 2021-08-19
  • 2021-08-15
  • 2021-11-12
  • 2022-12-23
  • 2021-04-18
相关资源
相似解决方案