当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 我设计一个下拉列表框,动态取数据库中某表值,我该怎么办? 例如: 表:duty 有个字段 duty_number duty_name 我要将所有值加入到下拉列表框,实际值为duty_number;显示值为duty_name 我该怎么办? ......
 ·代某作弊站站长向大力等高手    »显示摘要«
    摘要: 看到一文件有10g之巨,直接删除之。因为sqlserver还在用,当然删除不掉。 结果启动dos,在dos下删除了database.ldf文件....... 结果是可想而知的........ 求数据库高手帮助,如成功,送一年免费vip贵宾帐号。提供电影,a片............. 救命啊!!! ......


怎样提出每组的前五个记录,如果该组记录少于5个,则有多少记录显示多少记录

怎样提出每组的前五个记录,如果该组记录少于5个,则有多少记录显示多少记录  
   
   
  比如数据格式   如下:  
  dept       title      
  001         x01          
  001         x02  
  001         x03  
  001         x04  
  001         x05  
  001         x06  
  001         x07  
  002         x21  
  002         x22  
  003         x31  
  003         x32  
  003         x33  
  003         x34  
  003         x35  
  003         x36  
  003         x37  
   
   
  ==================  
  求   怎样实现   查询的列表如下结果  
   
  dept       title      
  001         x01          
  001         x02  
  001         x03  
  001         x04  
  001         x05  
  002         x21  
  002         x22  
  003         x31  
  003         x32  
  003         x33  
  003         x34  
  003         x35  
   
  ======================  
   
  语句怎么写啊

NO.1   作者: sdhdy

select   *   from   tablename   a   where   title   in   (select   top   5   tilte   from   tablename   where   a.dept=dept   )

NO.2   作者: letsflytogether

select   *   from   表名   where   title   in   (select   top   5   title   from   表名   where   dept   in   (select   distinct   dept   from   表名))

NO.3   作者: tj_dns

select   *   from   tablename   a   where    
  title   in   (select   top   5   title   from   tablename   where   dept=a.dept   order   by   title   )  
 

NO.4   作者: eastpond

create   table   #temp(dept   char(4),title   char(4))  
   
  insert   into   #temp(dept,title)   values(001,x01)  
  insert   into   #temp(dept,title)   values(001,x02)  
  insert   into   #temp(dept,title)   values(001,x03)  
  insert   into   #temp(dept,title)   values(001,x04)  
  insert   into   #temp(dept,title)   values(001,x05)  
  insert   into   #temp(dept,title)   values(001,x06)  
  insert   into   #temp(dept,title)   values(001,x07)  
  insert   into   #temp(dept,title)   values(002,x21)  
  insert   into   #temp(dept,title)   values(002,x22)  
  insert   into   #temp(dept,title)   values(003,x31)  
  insert   into   #temp(dept,title)   values(003,x32)  
  insert   into   #temp(dept,title)   values(003,x33)  
  insert   into   #temp(dept,title)   values(003,x34)  
  insert   into   #temp(dept,title)   values(003,x35)  
  insert   into   #temp(dept,title)   values(003,x36)  
  insert   into   #temp(dept,title)   values(003,x37)  
         
  select   *   from   #temp   a   where   title   in   (select   top   5   title   from   #temp   where   a.dept   =   dept   order   by   title   )  
   
  drop   table   #temp;  
   
  sdhdy(大江东去...)、tj_dns(愉快的登山者)结果正解.  
  dept   title    
  ----   -----    
  001     x01    
  001     x02    
  001     x03    
  001     x04    
  001     x05    
  002     x21    
  002     x22    
  003     x31    
  003     x32    
  003     x33    
  003     x34    
  003     x35    
   
   
 

NO.5   作者: killxtt

我发现大家都不喜欢用游标阿,是不是因为效率太低,而且比较复杂

NO.6   作者: pengdali

select   *   from   你的表   a   where   title   in   (select   top   5   title   from   你的表   where   dept=a.dept)

NO.7   作者: maoxianqiang

用游标+臨時表(如果字段很多)  
   
 

NO.8   作者: zjcxc

游标效率太低,也不能利用索引,数据多的时候速度明显地慢:  
   
  所以,能够不用游标,就不要用.

NO.9   作者: zjcxc

 
  游标效率太低,也不能利用索引,数据多的时候速度明显地慢:  
   
  所以,能够不用游标,就不要用.


    摘要: 在先等待:javascript中的去处字符串中的空格是那个函数 怎么用? ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE