tb  
 
f1  f2    f3      f4  
--------------------------  
1      x    001    1001  
2      x    002    1002  
3      x    003    1003  
4      w    xyz    1003  
 
取的结果    如果是f3最大值    
     x  
   --------------  
   003  
 
取的结果    如果查询f3的  x    
   
   w          f4  
   --------------  
   003    1003  

解决方案 »

  1.   

    1,是不是说查询f2列,如果f3是所有记录的最大值,那么f2列显示最大值,否则显示f3?
    如果是这样的话.SELECT f1,ISNULL(NULLIF(f3,mf3),mf3) f2,f3,f4
    FROM tb a
    LEFT JOIN (SELECT MAX(f3) mF3 FROM tb) b
    ON 1=12,没看明白.楼主给点语言描述可以吗?
      

  2.   

    f2 是查询的条件 
     
    1. 相当正常 select max(f3) from tb where f2='x' and f4='1001'
     
      例 我现在找 f2 中条件是x ,取的f3的最大值2.相当正常   select w ,f4   from tb where f2='w' and f4='1001'
      

  3.   

    1. 相当正常 select max(f3) from tb where f2='x'  上述写多加了and f4='1001' ,应该去掉
      

  4.   

    搂主是希望F2的值当作参数吗?F2值不同时得到不同的MAX(f3)?
      

  5.   


     
     
    1. 相当正常 select max(f3) from tb where f2='x'  
    tb  
     
    f1  f2    f3      f4  
    --------------------------  
    1      x    001    1001  
    2      x    002    1002  
    3      x    003    1003  
    4      w    xyz    1003  
     
     得到结果
         x  
       --------------  
       003  
     
     2.相当正常   select w ,f4   from tb where f2='w' and f4='1001'
       
     得到结果
         x  
       --------------  
       003  
       w          f4  
       --------------  
       003    1003
      

  6.   

    我说的不明白 
    tb  
     
    f1  f2    f3      f4  
    --------------------------  
    1   x    001    1001  
    2   x    002    1002  
    3   x    003    1003  
    4   w    xyz    1003   我要 取到 F2 为 X 的最大值
      

  7.   

    我要 取到 F2 为 X的f3的最大值
      

  8.   

    Create table testtb
    (
        f1 int,
        f2 char(1),
        f3 varchar(4),
        f4 varchar(10)    
    )
    insert into testtb
    select 1,'x','001','1001' union all
    select 2,'x','002','1001' union all
    select 3,'x','003','1001' union all
    select 4,'w','xyz','1001' select * from  testtbselect max(f3) as f3 from testtb where f2='x'这样?  我不知道你各个字段的类型
      

  9.   

    樓主是不是這個意思??
    Create Table tb
    (
    f1 Int,
    f2 Char(1),
    f3 Varchar(4),
    f4 Varchar(10))
    Insert Into tb
    Select 1,'x','001','1001' Union All
    Select 2,'x','002','1001' Union All
    Select 3,'x','003','1001' Union All
    Select 4,'w','xyz','1001' 
    GO
    Select Max(f3) As f3 From tb Where f2='x'Select A.f3,A.f4 From tb A
    Inner Join
    (Select f2,Max(f3) As f3 From tb Where f2='x' Group By f2) B
    On A.f2=B.f2 And A.f3=B.f3
    GO
    Drop Table tb
    --Result
    /*
    f3
    003f3 f4
    003 1001
    */