表格应用程序
id | user_id | created_at
1 2 week1
2 3 week1
3 2 week2
4 5 week3
5 3 week3
6 2 week4
计算上周有申请但不是当前周的用户。因此,例如对于第2周,它将返回1,对于第3周,它将返回1,对于第4周,它将返回2.
查询的预期结果:
week | difference
week2 1
week3 1
week4 2
我可以在单个查询中使用UNION以某种方式执行此操作吗?我此刻有点迷失。
我知道我可以每周进行一次查询,然后进行多次查询,但是可以一次性完成吗?
答案 0 :(得分:0)
SELECT created_at as week, count(user_id) as differences
FROM Applications
WHERE created_at <> 'week1'
GROUP BY created_at