sql 按时间条件查询count的问题
我这里的数据默认就是 getdate()生成的
所以数据
都是
2011-6-10 17:50:03
2011-6-10 17:20:06
这样的
所以我这里用getdate()也把具体的时间带上去。。。 所以导致 查询的count为0
这里如何查询 当天的呢?mydate=?这个地方的条件怎么写哇?
作者: lijing3333 发布时间: 2011-06-10
作者: chuanzhang5687 发布时间: 2011-06-10
作者: l3143344 发布时间: 2011-06-10
你想查什么东西?
作者: chuanzhang5687 发布时间: 2011-06-10
select * from xxx where UserID=2127 and mydate=convert(nvarchar,getdate(),23)
作者: chuanzhang5687 发布时间: 2011-06-10
select count(1) from xxx where UserID=2127 and mydate=convert(nvarchar(50),getdate(),23)
你这个也查不出来 我先也是这样做的 现在我改成这样就可以查询出来了
不知道有没简单的办法
select count(1) from xx where UserID=2127 and (select convert(varchar(10),mydata,120)) = (select convert(varchar(10),getdate(),120))
作者: lijing3333 发布时间: 2011-06-10
select count(1) from xxx where UserID=2127 and mydate=convert(char(20),getdate(),120)
作者: ff284996867 发布时间: 2011-06-10
select count(1) from xxx where UserID=2127 and convert(varchar(10),mydate,120)=convert(varchar(10),getdate(),120)
作者: maco_wang 发布时间: 2011-06-10
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
……
同感
作者: qq623932737 发布时间: 2011-06-10
convert(nvarchar(50),mydate,23)=convert(nvarchar(50),getdate(),23)
作者: l3143344 发布时间: 2011-06-10
作者: chuanzhang5687 发布时间: 2011-06-10
作者: zhou_xuexi 发布时间: 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
作者: yubofighting 发布时间: 2011-06-10