SQL Server如何从Date获取当前Quarter的字段数?

时间:2013-07-11 06:36:05

标签: sql-server tsql date

我很难组装SQL语句。场景/要求是这样的:我需要计算当前季度的字段数。

SELECT COUNT(fieldname) AS Hits 
FROM tablename 
WHERE DatePosted = (Current Quarter)

我想获得当前季度的点击次数。

这可能吗?

1 个答案:

答案 0 :(得分:6)

select count(fieldname) as Hits 
from tablename
where datepart(q,DatePosted) = datepart(q,getdate())
and year(DatePosted) = year(getdate())