sql 按时间条件查询count的问题

lijing3333 2011-06-10 04:39:58
select count(1) from xxx where UserID=2127 and mydate=getdate()

我这里的数据默认就是 getdate()生成的

所以数据
都是
2011-6-10 17:50:03
2011-6-10 17:20:06
这样的

所以我这里用getdate()也把具体的时间带上去。。。 所以导致 查询的count为0

这里如何查询 当天的呢?mydate=?这个地方的条件怎么写哇?
...全文
338 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yubofighting 2011-06-10
  • 打赏
  • 举报
回复

select count(1) from xxx where UserID=2127 and mydate=CONVERT(varchar(100), GETDATE(), 23)


另附:http://blog.csdn.net/yubofighting/archive/2010/10/13/5938103.aspx
zhou_xuexi 2011-06-10
  • 打赏
  • 举报
回复
select count(1) from xxx where UserID=2127 and datediff(day,mydate,getdate())=0
chuanzhang5687 2011-06-10
  • 打赏
  • 举报
回复
[code=SQL]select count(1) from xx where UserID=2127 and convert(varchar(10),mydata,120) = (convert(varchar(10),getdate(),120)code]
l3143344 2011-06-10
  • 打赏
  • 举报
回复
select count(1) from xxx where UserID=2127 and
convert(nvarchar(50),mydate,23)=convert(nvarchar(50),getdate(),23)
qq623932737 2011-06-10
  • 打赏
  • 举报
回复
[Quote=引用楼主 lijing3333 的回复:]
select count(1) from xxx where UserID=2127 and mydate=getdate()

我这里的数据默认就是 getdate()生成的

所以数据
都是
2011-6-10 17:50:03
2011-6-10 17:20:06
这样的

所以我这里用getdate()也把具体的时间带上去。。。 所以导致 查询的count为0

……
[/Quote]

同感
叶子 2011-06-10
  • 打赏
  • 举报
回复

select count(1) from xxx where UserID=2127 and

convert(varchar(10),mydate,120)=convert(varchar(10),getdate(),120)
ff284996867 2011-06-10
  • 打赏
  • 举报
回复
select count(1) 
from xxx
where UserID=2127 and mydate=convert(char(20),getdate(),120)
lijing3333 2011-06-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 l3143344 的回复:]
select count(1) from xxx where UserID=2127 and mydate=convert(nvarchar(50),getdate(),23)
[/Quote]

你这个也查不出来 我先也是这样做的 现在我改成这样就可以查询出来了
不知道有没简单的办法

select count(1) from xx where UserID=2127 and (select convert(varchar(10),mydata,120)) = (select convert(varchar(10),getdate(),120))
chuanzhang5687 2011-06-10
  • 打赏
  • 举报
回复
select * from xxx where UserID=2127 and mydate=convert(nvarchar,getdate(),23)
chuanzhang5687 2011-06-10
  • 打赏
  • 举报
回复
你想查什么东西?
l3143344 2011-06-10
  • 打赏
  • 举报
回复
select count(1) from xxx where UserID=2127 and mydate=convert(nvarchar(50),getdate(),23)
chuanzhang5687 2011-06-10
  • 打赏
  • 举报
回复
擦 getdate()是当前时间啊 你怎么能查出来数据?

34,590

社区成员

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

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