现有一表,字段有a,b,c
a:数字
b:日期
c:数字例
a  b          c
1  2007-01-23 3
1  2007-06-01 4
1  2003-04-06 3
2  2006-02-03 3
2  2005-01-04 4能不能查询出c=x,如果存在多条a相同的记录,只保留b最大的一条。

解决方案 »

  1.   

    select top 1 *
    from tmp_test
    where c =3
    order by b desc
      

  2.   

    "select top 1 * from tmp_test where c ="+x+" order by b desc"
      

  3.   

    如果不限定条件把c=x去掉呢?
    如何保证结果集里面a相同的记录只保留日期最大的一条?
      

  4.   

    select A.A,A.B,A.C from
    (select max(B) as T1,C as T2 from tmp_test group by C) B left join tmp_test A on B.T1=A.B and B.T2 = A.C
      

  5.   

    "select a,max(b) as c from tmp_test group by a"
      

  6.   

    这时,字段b被改名为c了,注意引用时要用c来读取数值!
      

  7.   

    select a,max(b) as c from tmp_test group by a