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

    摘要: using system; using system.drawing; using system.collections; using system.componentmodel; using system.windows.forms; using system.data; using system.data.oledb; namespace datatest { public cl......
 ·datareport     »显示摘要«
    摘要: 新学datareport,找了一段程序运行报表功能出现report width is larger than the paper width错误提示,试修改reportwidth等属性都没用, ......


求一SQL语句(要求效率高)

从一个表检索出满足如下条件的Code列表:  
   
  Code   Dif   YM  
  111     1     200501  
  111     0     200506  
  222     1     200301  
  333     1     200512  
   
  如果当前年月为200508,要求检索出的列表为222  
  如果当前年月为200505,要求检索出的列表为111,222  
  如果当前年月为200512,要求检索出的列表为222,333  
   
  既如果一个code的最大YM的那一条记录的数据的Dif为1,则检索出。

NO.1   作者: wutao411

declare   @string   varchar(100)    
   
  select   @string=isnull(@string,)   +   code   +,     from   table   where   ym<=当前年月   and   dif=1  
  select   @string  
 

NO.2   作者: vivianfdlpw

declare   @tb   table  
  (  
      Code   int,  
      Dif   int,  
      YM   int  
  )  
  insert   @tb  
  select   111,1,200501   union  
  select   111,0,200506   union  
  select   222,1,200301   union  
  select   333,1,200512    
   
  --查询  
   
  declare   @YM   int  
  set   @YM=200512  
   
  select   distinct   code   from   @tb   t  
  where   (select   Dif    
                    from   @tb   A  
                        where   A.code=t.code  
                                    and  
                                    A.YM=(select   max(Ym)    
                                                    from   @tb    
                                                          where   code=A.code    
                                                                      and   YM<=@YM)  
              )=1  
   
  --结果  
  /*  
  code                  
  -----------    
  222  
  333  
   
   
  */


 ·[生日]呵呵,自己祝贺一下先    »显示摘要«
    摘要: 呵呵,今天是小弟24岁的生日,可惜到现在还和24年前一样菜......,哎无语了 学编程也快一年了,在这一年里得到了兄弟们的很多帮助,也在这里谢谢大家了 这是偶阳历生日,偶有阴历生日是8月15,哭呀........,大过节的不能全家,还要自己过生日,郁闷了!! ......
» 本期热门文章:

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