select max(col3),max(app_date) 
from  (select col3,min(approved_date) app_date 
       from   csms_m_vendor 
       where  code1='A0001' 
       and    code2='B0002'
       group by col3) 
==>
select max(col3),max(app_date) from   csms_m_vendor 
       where  code1='A0001' 
       and    code2='B0002'

解决方案 »

  1.   

    不好意思,我前面没考虑到别名和列名相同,max取的是别名的,如下:max(my_date),
    col3的max只是因为group by而已。
    ----------------------------------------
    select max(col3),max(my_date) 
    from  (select col3,min(app_date) my_date 
           from   csms_m_vendor 
           where  code1='A0001' 
           and    code2='B0002'
           group by col3) 
    ----------------------------------------
    如果是
    select max(col3),max(app_date) from   csms_m_vendor 
           where  code1='A0001' 
           and    code2='B0002'
    这样的话得到的不能保证是最“新”的值了。