我创建了下面的代码,它为我提供了按公司细分的唯一用户数。我想添加一个日期修饰符,它有两列,一列用于“上周”,另一列用于“2 周前”。我希望这些列根据字段“users.date”分别显示前一周日期和前一周的活跃用户。任何帮助都会很棒。我正在使用 SQL Server Management Studio 2008 R2。
--Active Users
SELECT company.companyName as 'Group Name',
COUNT(distinct users.userid) [Count]
FROM Users, Company
WHERE
Jobstate = '6'
and company.companyID = users.companyid
and company.companyID in (1,4,31)
GROUP BY company.companyName
目前我收到这个结果:
Group Name | Count |
------------------------
Company 1 | 104 |
Company 2 | 74 |
Company 3 | 46 |
我希望看到的是:
Group Name | Last Week | 2 Weeks Ago |
--------------------------------------
Company 1 | 14 | 16 |
Company 2 | 7 | 12 |
Company 3 | 4 | 8 |