查询一个表中某时间字段的最大值,并判断该记录的状态(1、2)是否等于2。

解决方案 »

  1.   

    select max(时间字段) from tb where  状态=2
      

  2.   

    if exists(select 1 from tb where 时间字段=(select top 1 时间字段 from tb order by 时间字段 desc) and 状态=2)
      print '是'
    else
      print '否'
      

  3.   

    SELECT 状态 FROM TB WHERE 时间字段=(select max(时间字段) from tb )
      

  4.   

    if exists(select 1 from tb where 时间字段=(select max(时间字段) from tb) and 状态=2)
      print '是'
    else
      print '否'
      

  5.   

    select 状态 from tb where 时间 between t1 and t2 
      

  6.   

    select field_state from table order by field_time desc limit 1