我在sql中用select msg from cpzq where id in (select max(id) from cpzq)
查询,其中id nvarchar(20),msg nvarchar(256),查询的结果不能返回最大值

解决方案 »

  1.   

    select msg
      from cpzq
     where id in
      (select max(id) as id --<----how about add this
         from cpzq)
      

  2.   

    select max(id) from cpzq 这个子查询能不能返回最大ID?使用语句:
    select msg from cpzq where id = (select max(id) id from cpzq)
    or
    select msg from cpzq where id in (select max(id) id from cpzq)
      

  3.   

    to xx9yk and thing 都不行
      

  4.   

    我的是 ORACLE 语法,
    xx9yk的是 SQL SERVER
      

  5.   

    你的 select max(id) from cpzq 能不能返回最大值
      

  6.   

    select msg from cpzq where id = (select max(id) as id from cpzq)
      

  7.   

    作个转换把
    select msg from cpzq where to_number(id) in (select max(to_number(id)) from cpzq)
    //to_number是一个字符转换为数字的函数,不知道你用的数据库是什么,不过也应该有类似的函数
      

  8.   

    你用 CAST 或 CONVERT 把ID转换成数字型的进行比较,这两个函数我不太会用(我用ORACLE, 和楼上一样:))。select msg from cpzq where cast(id as int) = (select max(cast(id as int)) from cpzq)
      

  9.   

    谢谢,可以了
    select msg from cpzq where 
    (CAST( id AS int(4))) in (select max (CAST(id AS int(4))) from cpzq)