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

    摘要: delphi直接读文本文件然后逐行读取数据的程序怎么写?急急急! ......
    摘要: vb中怎么调用? 并且因为通用性问题怎么使别人也能用,把自己的宏一起copy过去?宏放在哪个目录里的? ......


很简单但不容易回答的问题

declare   @tb1   table   (item   varchar(10),[date]   char(8),[money]   decimal)  
  insert   into   @tb1  
  select   001,             20050617,           10   union   all  
  select   002,             20050617,           20   union   all  
  select   003,             20050617,           33   union   all  
  select   001,             20050618,           11   union   all  
  select   002,             20050618,           21   union   all  
  select   001,             20050619,           12   union   all  
  select   003,             20050619,           32   union   all  
  select   001,             20050620,           13   union   all  
  select   002,             20050620,           22   union   all  
  select   003,             20050620,           31  
   
  select    
          a.*  
  from  
          @tb1   a  
  where  
          a.[date]   =   (select   max([date])   from   @tb1   where   item=a.item)  
   
   
   
   
  item               date           money                                  
  ----------   --------   --------------------    
  003                 20050620   31  
  002                 20050620   22  
  001                 20050620   13  
   
   
   
   
   
  假设你是SQL   SERVER,你是怎么个顺序来执行这个查询?先...再...然后...?

NO.1   作者: vivianfdlpw

Ctrl+L参看执行计划

NO.2   作者: iwl

先是子查询   select   max([date])   from   @tb1   where   item=a.item得到   max值  
  然后select     a.*     from           @tb1   a   where

NO.3   作者: iwl

这个item=a.item是什么意思?  
   
  item表示@tb1里面的字段,a.item表示@tb1   a里面的字段。这实际上就是一个自联接,你可以吧它理解为两个不同的表。  
   
  上面的语句可以差分为:  
        select   变量=max([date])   from   @tb1,@tb1   a   where   item=a.item  
   
        select     *   from           @tb1   where         [date]   =变量  
   
   
   
   
   
 

NO.4   作者: lllhhhqqq

在  
  select    
          a.*  
  from  
          @tb1   a  
  时查出   a.item  
  同时   a.item作为子查询where的条件   在子查询里优先级最高  
  作为   select   max([date])   from   @tb1的条件  
  最后查询结果和外面的a.[date]字段做匹配

NO.5   作者: frostnet

先   select   max([date])   from   @tb1   where   item=a.item  
   
  再   select     a.*     from     @tb1   a   where

NO.6   作者: comefirst

先取A  
  然后选择最大  
  再select   a.*

NO.7   作者: lllhhhqqq

上面写的很明白了   不要以c++的思维去考虑sql   sql是结构查询  
  select   max([date])   from   @tb1   where   item=a.item查出来的东西当然是一条  
  但item一共有三个   分三次每次一条   最后外面总的记录也是三条


    摘要: 多少钱一个页面? ......
» 本期热门文章:

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