日期:2014-05-18  浏览次数:20587 次

跪求一条sql语句,如何取得"今日"的发表的数量
数据库是MS-sql
简单的描述就是这样:在表里,
字段有:id     title     content     createTime
createTime   是发表时间,datetime类型
取得发表的文章的全部数量可以用sum,
可是要取得今日的发表数量,如何写这个sql语句??(比如取得今天8月27日发表的文章数量)


兄弟们帮帮忙,立刻给分!

------解决方案--------------------
select count(*) from tablename where createTime > =getdate()
------解决方案--------------------
这样更准一些:
select count(*) from tablename where createTime> =Convert(datetime,year(getdate())+ '- '+month(getdate())+ '- '+day(getdate()))
------解决方案--------------------
select count(*) from tablename where convert(char(10),createTime,20) = convert(char(10),getdate(),20)
------解决方案--------------------
select count(*) from tablename where createTime > =getdate().toshortstring()

------解决方案--------------------
select count(id) from tablename where createTime> = CAST(SUBSTRING(CAST(StartDateTime AS VarChar), 0, 11) AS DateTime) AND createTime < DATEADD(Day,1,CAST(SUBSTRING(CAST(StartDateTime AS VarChar), 0, 11) AS DateTime))
------解决方案--------------------
select count(id) from tablename where createTime> = CAST(SUBSTRING(CAST(getdate() AS VarChar), 0, 11) AS DateTime) AND createTime < DATEADD(Day,1,CAST(SUBSTRING(CAST(getdate() AS VarChar), 0, 11) AS DateTime))