· 4 years ago · Jan 22, 2021, 05:38 PM
1CREATE table IF NOT EXISTS offer (
2 customer_id INT NOT NULL,
3 open_dt DATE NOT NULL
4);
5
6INSERT INTO offer (customer_id, open_dt)
7VALUES
8(1, '2020-09-01'),
9(1, '2020-10-04'),
10(1, '2020-11-01'),
11(2, '2020-09-16'),
12(3, '2020-10-31'),
13(4, '2020-10-29'),
14(4, '2020-11-01'),
15(5, '2020-11-07'),
16(6, '2020-11-12'),
17(7, '2020-11-14'),
18(8, '2020-12-30');
19
20SELECT count(DISTINCT customer_id) FROM offer AS sempt
21WHERE open_dt between '2020-09-01' and '2020-10-31';
22
23
24SELECT count(DISTINCT customer_id) FROM offer AS oct
25WHERE open_dt between '2020-10-01' and '2020-11-30';
26
27SELECT count(DISTINCT customer_id) FROM offer AS nov
28WHERE open_dt between '2020-11-01' and '2020-12-31';
29
30SELECT count(DISTINCT customer_id) FROM offer AS dec
31WHERE open_dt between '2020-12-01' and '2021-01-31';
32
33
34
35
36
37