Select * from TabSchedule where datediff(minute,getdate(),开始时间) <5 
/*
  datediff(minute,getdate(),开始时间) <5 --这句的意思就是现在的时间和TabSchedule表里的开始时间这个字段相差的分钟数小于5分钟
整句话就是挑选出表TabSchedule里 开始时间字段与现在时间差在5分钟内的记录
*/

解决方案 »

  1.   

    select a.title,a.username,b.adddate from tablename a,(select max(adddate) adddate from tablename where        tablename.title=a.title) b 
    这个写法很不好 会出错的。
    写法如下-- =========================================
    -- -----------t_mac 小编-------------
       ---希望有天成为大虾---- 
    -- =========================================
    --第一个例子
    IF OBJECT_ID('tablename') IS NOT NULL
      DROP TABLE tablename
    GO
    CREATE TABLE tablename(title varchar(100),username varchar(10),adddate datetime)
    go
    insert into tablename
    select 'a','j','2009-7-11 18:47' union all
    select 'a','k','2009-7-11 18:30' union all
    select 'a','e','2009-7-11 18:39' union all
    select 'c','f','2009-7-11 18:37' union all
    select 'c','g','2009-7-11 18:39' 
    go
    select title,a.username,(select max(adddate) adddate from tablename where tablename.title=a.title) from tablename a
     
    /*------------
    title                                                                                                username   
    ---------------------------------------------------------------------------------------------------- ---------- -----------------------
    a                                                                                                    j          2009-07-11 18:47:00.000
    a                                                                                                    k          2009-07-11 18:47:00.000
    a                                                                                                    e          2009-07-11 18:47:00.000
    c                                                                                                    f          2009-07-11 18:39:00.000
    c                                                                                                    g          2009-07-11 18:39:00.000(5 行受影响)
    -------*/
      

  2.   

    这个程序的作用就是运行后
    提示在现在这个时刻的五分钟内有事情的username会选出来的
    -- =========================================
    -- -----------t_mac 小编-------------
       ---希望有天成为大虾---- 
    -- =========================================
    --第一个例子
    IF OBJECT_ID('TabSchedule ') IS NOT NULL
      DROP TABLE TabSchedule 
    GO
    CREATE TABLE TabSchedule (username varchar(10),开始时间 datetime)
    go
    insert into TabSchedule
    select 'a','2009-7-11 18:45'  union all
    select 'b','2009-7-11 18:46'  union all
    select 'c','2009-7-11 18:47'  union all
    select 'd','2009-7-11 18:49'  union all
    select 'e','2009-7-11 18:31'  
    goSelect * from TabSchedule where datediff(minute,getdate(),开始时间) <5 
    /*
    username   开始时间
    ---------- -----------------------
    a          2009-07-11 18:45:00.000
    e          2009-07-11 18:31:00.000(2 行受影响)*/
    a
      

  3.   

    你的问题都是实际问题,要结合实际需求来解释。要解释sql语句需要结合表结构,单从sql语句反推回去,没什么实际意义。
      

  4.   

    修改 
    你第一个的写法不好 直接输入会出错 稍微修改下酒对了 意思是一样的
    IF OBJECT_ID('tablename') IS NOT NULL
      DROP TABLE tablename
    GO
    CREATE TABLE tablename(title varchar(100),username varchar(10),adddate datetime)
    go
    insert into tablename
    select 'a','j','2009-7-11 18:47' union all
    select 'a','k','2009-7-11 18:30' union all
    select 'a','e','2009-7-11 18:39' union all
    select 'c','f','2009-7-11 18:37' union all
    select 'c','g','2009-7-11 18:39' 
    go
    select title,username,adddate from tablename a where adddate in(
    select max(adddate) adddate from tablename where title=a.title) 
    /*
    title                                                                                                username   adddate
    ---------------------------------------------------------------------------------------------------- ---------- -----------------------
    c                                                                                                    g          2009-07-11 18:39:00.000
    a                                                                                                    j          2009-07-11 18:47:00.000(2 行受影响)
    */
    意思就是对同一片文章 提交最晚的那个时间
      

  5.   


    呵呵,这些语句是看了李天平那本亮剑<<.NET.+.NET深入体验与实战精要>>
    就列了一下,实际当中不知道如何用..................
      

  6.   

    还有一个问题~~~~~修改时间字段的小时部分
    --把所有时间2006-11-1的数据23点修改为21点update ad browse 20061101 set browsetime='2006-11-01 21'+
    substring(convert(varchar(30),browsetime,8),3,7)
    where datepart(hour,browsetime)=23这句sql是否有问题啊???
    browse这里?怪
      

  7.   

    update ad 
    set browsetime=DATEADD(HOUR,-2,browsetime)
    where datepart(hour,browsetime)=23 
    这样就可以 把所有小时为23点的时候 改成21点