tb:
col1     col2
a001      aa
a003      bb
a05       cc
a0322     dd
a01       eecol1为主键...主键是由 "a" + 数字组成
我每次要找到最大的 值  如上我要找a0322
得到记录为:
col1    col2
a0322   eee
   

解决方案 »

  1.   

    select * from tb where col1=(select max(col1) from tb)
      

  2.   

    select max(col1),col2 from tb group by col2
      

  3.   

    select * from tb a 
    where not exists(select 1 from tb 
           where cast(replace(col1,'a','') as int)>cast(replace(a.col1,'a','') as int))
      

  4.   


    SELECT TOP 1 * FROM TB ORDER BY COL1 DESC
      

  5.   

    SELECT MAX(coll) AS co11, MAX(Customer) AS col12 FROM Orders
      

  6.   

    select top 1 * from tb order by cast(substring(col1,2,len(col1)) as int) desc
      

  7.   

    SELECT TOP 1 * FROM tb ORDER BY cast(replace(col1,'a','') as int) desc
      

  8.   


    CREATE TABLE t1
    (
    col1 VARCHAR(10),
    col2 VARCHAR(10)
    )INSERT INTO t1
    SELECT 'a001','aa'
    UNION ALL
    SELECT 'a003','bb'
    UNION ALL
    SELECT 'a05','cc'
    UNION ALL
    SELECT 'a0322','dd'
    UNION ALL
    SELECT 'a01','ee'SELECT  col1,col2 
    FROM t1
    WHERE CAST(SUBSTRING(col1,2,LEN(col1)) AS INT )
    =(SELECT MAX(CAST(SUBSTRING(col1,2,LEN(col1)) AS INT )) FROM t1 )/*
    结果:
    col1       col2
    ---------- ----------
    a0322      dd(1 row(s) affected)
    */
      

  9.   

    SELECT TOP(1) * FROM table_name
    ORDER BY CAST(STUFF(col1, 1, 1, '') AS BIGINT) DESC
      

  10.   

    create table #ta(coll varchar(20),co2 varchar(20))
    insert into #ta
    select 'a11','aa' union all
    select 'a23','nn' union all
    select 'a45','ss' select * from #ta where coll in (select max(coll) from #ta)