我很难组装SQL语句。场景/要求是这样的:我需要计算当前季度的字段数。
SELECT COUNT(fieldname) AS Hits
FROM tablename
WHERE DatePosted = (Current Quarter)
我想获得当前季度的点击次数。
这可能吗?
答案 0 :(得分:6)
select count(fieldname) as Hits
from tablename
where datepart(q,DatePosted) = datepart(q,getdate())
and year(DatePosted) = year(getdate())