2009-10-12 08:00:00
2009-10-12 08:30:00
2009-10-12 17:59:00三个时间一条语句,取大于 2009-10-12 8:20:00 的最小时间(8:30:00),如果有小于8:20:00的时间,将显示null

解决方案 »

  1.   

    如果有小于8:20:00的时间,将显示null 什么意思?
      

  2.   

    if exists(select 1 from tb where time<'2009-10-12 8:20:00')
    print 'null'elseselect top 1 time from tb where time>'2009-10-12 8:20:00' order by time asc
      

  3.   

    create table tb(dt datetime)
    insert into tb values('2009-10-12 08:00:00') 
    insert into tb values('2009-10-12 08:30:00') 
    insert into tb values('2009-10-12 17:59:00')
    declare @dt as datetime
    set @dt =  '2009-10-12 08:20:00'if exists(select 1 from tb where dt < @dt)
       print 'null'
    else
       select top 1 dt from tb where dt > @dt order by dtdrop table tbgo/*
    null
    */
      

  4.   

    要么显示null,要么显示'2009-10-12 8:30:00'
      

  5.   


    if object_id('ta') is not null drop table ta
    go
    create table ta(sj datetime)
    insert into ta select
    '2009-10-12 08:00:00' union all select
    '2009-10-12 08:30:00' union all select
    '2009-10-12 17:59:00' 
    select distinct
    case when (select min(sj) from ta)< '2009-10-12 08:20:00' then null 
         else (select min(sj) from ta where sj>'2009-10-12 08:20:00')
    end
    from ta
    /*
    -----------------------
    NULL(1 行受影响)
    */
      

  6.   

    呵呵,楼主:你到底想怎么样?
    又要显示最小时间、又要显示NULL,又要一条语句?按照你的记录,最小时间肯定只有一条记录啊,怎么又要显示NULL ?
      

  7.   

    如果没有8:00:00就是null呀,如果有8:00:00肯定select 的出数据了,就是8:30:00呀
      

  8.   

    create table ta(sj datetime)
    insert into ta select
    '2009-10-12 08:00:00' union all select
    '2009-10-12 08:30:00' union all select
    '2009-10-12 17:59:00' --要么显示null,要么显示'2009-10-12 8:30:00' 
    select 
        (case when sj<>'2009-10-12 8:30:00'  then null 
             else sj end)    
    from ta
      

  9.   

    --如果有小于8:20:00的时间,将显示null
    --要么显示null,要么显示'2009-10-12 8:30:00' 
    select 
        (case when sj=(select min(sj) from ta where sj>'2009-10-12 8:20:00')  then sj
             else null end)    
    from ta
      

  10.   

    我写好了,这才是我需要的select time from (
    select min(time) as time from t_dakarecord 
    ) a 
    group by time having time>'2009-10-12 8:20:00'
      

  11.   

    create table ta(sj datetime)
    insert into ta select
    '2009-10-12 08:00:00' union all select
    '2009-10-12 08:30:00' union all select
    '2009-10-12 17:59:00' --如果有小于8:20:00的时间,将显示null
    --大于2009-10-12 8:20:00的最小时间
    select 
        (case when sj=(select min(sj) from ta where sj>'2009-10-12 8:20:00')  then sj
             else null end) '大于2009-10-12 8:20:00的最小时间'
    from ta--大于8:20:00的最小时间,不管日期是哪一天
    select 
        (case when sj=(select min(sj) from ta where convert(varchar(8),sj,8)>'08:20:00')  then sj
             else null end) '大于8:20:00的最小时间'
    from ta
      

  12.   

    --我写好了,这才是我需要的 select time from ( 
    select min(time) as time from t_dakarecord 
    ) a 
    group by time having time>'2009-10-12 8:20:00' 
    --好个屁,要这么多子查询干嘛呢?(结果也不对:无返回记录行)
    select min(time) as time from t_dakarecord 
    where time>'2009-10-12 8:20:00' 
    --这样还差不多