我数据库中有字段a  a中有数据:
QZC0609-001   
QWC0609-002 
ZY0609-003 
DY0609-004请问我想查询的是后面数字部份的最大的哪个数据值,在上面几个中,我想查出的是DY0609-004,
请SQL语句如何写,谢谢!

解决方案 »

  1.   

    --建立测试环境
    Create Table 表(f varchar(50))
    --插入数据
    insert into 表
    select 'QZC0609-001' union
    select 'QWC0609-002' union
    select 'ZY0609-003' union
    select 'DY0609-004'
    select * from 表
    --测试语句
    select  top 1 f from 表   order by (RIGHT (f,3)) desc
     
    --删除测试环境
    Drop Table 表
      

  2.   

    select  top 1 a from 表 order by (RIGHT (a,3)) desc