当前小时:select * from 表 where datediff(hh,列,getdate())=0

解决方案 »

  1.   

    select datediff(day,'2001-1-1','2002-1-1') 天
    select datediff(month'2001-1-1','2002-1-1') 月
    select datediff(year,'2001-1-1','2002-1-1') 年
      

  2.   

    select * from 表 where datediff(mi,列,getdate()) between 0 and 60
    select CONVERT(varchar(13),列,120),count(*) from 表 group by CONVERT(varchar(13),列,120)
    select CONVERT(varchar(10), getDate(),120) --不要时间2002-1-1
    select convert(char(8),getdate(),112) ----20020101
    select convert(char(8),getdate(),108)  ---06:05:05
      

  3.   

    select CONVERT(varchar(13),col,120),count(*) from table13 group by CONVERT(varchar(13),col,120)
      

  4.   

    select * from 表 tem where 时间列 between @你的开始时间 and 结束时间 and 时间列=(select max(时间列) from 表 where datediff(hh,时间列,tem.时间列)=0 and 时间列 between @你的开始时间 and 结束时间)
      

  5.   

    select * from 表 tem where 时间列 between @你的开始时间 and @结束时间 and 时间列=(select min(时间列) from 表 where datediff(hh,时间列,tem.时间列)=0 and 时间列 between @你的开始时间 and @结束时间)或:select * from 表 tem where 时间列=(select max(时间列) from 表 where datediff(hh,时间列,tem.时间列)=0 and 时间列 between @你的开始时间 and @结束时间)
      

  6.   

    比如我的表名为data,他的时间列为time,是不是下面的语句?
    select * from data a where time between(@starttime and @endtime) and time=(select max(time) from data where datediff(hh,time,a.time)=0 and time between(@startime and @endtime))
      

  7.   

    参考这个:
    http://expert.csdn.net/Expert/topic/2437/2437014.xml?temp=.67857
    交流]自增号
    应用举例
    eg1: 
    create table t(日期 char(8),请假人数 int)
    insert t select '20031001',3
    Union all select '20031003',2
    Union all select '20031004',1
    Union all select '30031031',5
    要列出2003年10月每一天的请假人数,若没有,以0表示。Select convert(char(8),dateadd(day,id,'20031001'),112),IsNull(t.请假人数,0) from 
    (Select top 31 (select sum(1) from sysobjects where name<= a.name)-1 as id from sysobjects a) bb
    left join t on convert(char(8),dateadd(day,id,'20031001'),112) = t.日期
      

  8.   

    看不懂,能用简单的sql语句解决吗?
      

  9.   

    SELECT * FROM tblName WHERE 时间列 BETWEEN (COVNERT(CONVERT(VARCHAR(10),时间列,121) AS DATETIME , dayadd(h,1,CONVERT(CONVERT(VARCHAR(10),时间列,121) as datetime)
    --把时间转化成 字符而 后重新转化为时间,比较麻烦是真事!
      

  10.   

    单用户数据搜索可以做到,多用户数据数据搜索怎么做。
    select * from data a where time between @starttime and @endtime and time=(select max(time) from data where datediff(hh,time,a.time)=0 and time between @startime and @endtime)
    如果用户号字段为userid,按用户号分类 (group by userid)怎么做?????
      

  11.   

    select * from data a where time between @starttime and @endtime 
    and time=(select max(time) from data where datediff(hh,time,a.time)=0 and
     time between @startime and @endtime and userid=a.userid)
      

  12.   

    谢谢。还有个问题,解决加分。
    我原来把SQL SERVER 的程序和数据都放到系统盘中了,现在想把数据放到别的盘上,有方便点的方法吗?