---------------------------简单SQL语句,关于时间查询?----------------------------------

hufanxp 2004-12-31 01:56:11
T1( nProID, BgnTime, EndTime nPre, nLast )
1 2001-9-5 12:12:00 2001-9-5 13:12:00 15 10
2 ...............................

T2 (nUserID userDate, userTime )
1 2001-9-5 1900-01-01 12:13:00
2 2001-9-5 1900-01-01 12:14:00
1 2001-9-6 1900-01-01 12:13:00

nPre,nLast分别表示分钟,int

在T2种用户得时间被分成2个字段 userData为日期 userTime为时间
现在给定一个 nProID,根据T1中得时间stdTime,需要得到
[BgnTime-nPre,2001-9-5 13:12:00+nLast]的时间内,T2中所有nUserID
...全文
218 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
didoleo 2004-12-31
  • 打赏
  • 举报
回复
--先申明一个变量@nProID
select nUserID from
T2
where
cast(userDate+' '+convert(char(10),userTime,108) as datetime)
>=(select dateadd(mi,-nPre,BgnTime) from T1 where nProID=@nProID)
and
cast(userDate+' '+convert(char(10),userTime,108) as datetime)
<=(select dateadd(mi,nLast,EndTime) from T1 where nProID=@nProID)
didoleo 2004-12-31
  • 打赏
  • 举报
回复

select nUserID from
T2
where
cast(userDate+' '+convert(char(10),userTime,108) as datetime)
>=(select dateadd(mi,-nPre,BgnTime) from T1 where nProID=@nProID)
and
cast(userDate+' '+convert(char(10),userTime,108) as datetime)
<=(select dateadd(mi,nLast,EndTime) from T1 where nProID=@nProID)
xueguang 2004-12-31
  • 打赏
  • 举报
回复
declare @A datetime,@B datetime
select @A=dateadd(minure,-nPre,BgnTime),@B=dateadd(minute,nLase,EndTime) from T1 where nProID=?
select nUserID from T2 where userDate+' '+userTime between @A and @B
hufanxp 2004-12-31
  • 打赏
  • 举报
回复
给定一个ProID(如nProID=1)
在T2中查询用户的刷卡时间在[BgnTime-nPre, EndTime+nLast]时间范围内的所有记录

hufanxp 2004-12-31
  • 打赏
  • 举报
回复
nPre, nLast 代表分
didoleo 2004-12-31
  • 打赏
  • 举报
回复
nPre, nLast
15 10
代表的时?分?秒?
wzh1215 2004-12-31
  • 打赏
  • 举报
回复
这么难懂,晕!
hufanxp 2004-12-31
  • 打赏
  • 举报
回复
需要得到[BgnTime-nPre,EndTime+nLast]的时间内,T2中所有nUserID

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧