90 days range using SQL server

前端 未结 2 649
渐次进展
渐次进展 2021-01-23 05:39

is there a way in SQL server that i can count the items 90 days prior to the inception date and the items 90 days after the inception date. Example:

select
site,         


        
相关标签:
2条回答
  • 2021-01-23 06:14

    Use:

      SELECT t.site,
             SUM(CASE WHEN t.date BETWEEN DATEADD(dd, -90, '2009-10-01') AND DATEADD(ss, -1, '2009-10-01') THEN 1 ELSE 0 END) AS numPrior,
             SUM(CASE WHEN t.date BETWEEN DATEADD(dd, 1, '2009-10-01') AND DATEADD(dd, 91, '2009-10-01') THEN 1 ELSE 0 END) AS numPost
        FROM YOUR_TABLE t
    GROUP BY t.site
    

    Tweak the DATEADD function and inception date as you need.

    0 讨论(0)
  • 2021-01-23 06:20

    http://msdn.microsoft.com/en-us/library/aa258267(SQL.80).aspx

    0 讨论(0)
提交回复
热议问题