|
@@ -121,15 +121,40 @@ SELECT COUNT(*) as c, icp_id, read_date FROM coup_prd.coupdatamaster
|
121
|
121
|
AND content_code = 'UN'
|
122
|
122
|
GROUP BY icp_id, read_date ORDER BY c DESC, read_date LIMIT 40;
|
123
|
123
|
|
124
|
|
-
|
|
124
|
+-- Get the range of dates present in the dataset
|
125
|
125
|
SELECT MIN(read_date) as min_date, MAX(read_date) as max_date FROM coup_prd.coupdatamaster;
|
126
|
126
|
|
|
127
|
+-- Because some people have multiple meters, for a variety of reasons, this query does not work
|
127
|
128
|
SELECT SUM(CASE WHEN cir.c > 365 THEN 1 ELSE 0 END), COUNT(*)
|
128
|
129
|
FROM
|
129
|
130
|
(
|
130
|
131
|
SELECT COUNT(*) as c, icp_id FROM coup_prd.coupdatamaster
|
131
|
|
- WHERE read_date >= to_date('01/01/2017','dd/mm/yyyy')
|
|
132
|
+ WHERE read_date >= to_date('01/01/2017','dd/mm/yyyy')
|
132
|
133
|
AND read_date < to_date('01/01/2018','dd/mm/yyyy')
|
133
|
134
|
AND content_code = 'UN'
|
134
|
135
|
GROUP BY icp_id ORDER BY c DESC
|
135
|
136
|
) AS cir;
|
|
137
|
+
|
|
138
|
+-- Find the number of ICPs with less than 360 days of data in 2017
|
|
139
|
+SELECT SUM(CASE WHEN cir.c < 360 THEN 1 ELSE 0 END), COUNT(*)
|
|
140
|
+FROM
|
|
141
|
+(
|
|
142
|
+ SELECT icp_id, COUNT(DISTINCT read_date) AS c FROM coup_prd.coupdatamaster
|
|
143
|
+ WHERE read_date >= to_date('01/01/2017','dd/mm/yyyy')
|
|
144
|
+ AND read_date < to_date('01/01/2018','dd/mm/yyyy')
|
|
145
|
+ AND content_code = 'UN'
|
|
146
|
+ GROUP BY icp_id ORDER BY c DESC
|
|
147
|
+) AS cir;
|
|
148
|
+
|
|
149
|
+-- Produces a table of all the icp's with at least 360 days of data, along with a column of days of data
|
|
150
|
+SELECT *
|
|
151
|
+FROM
|
|
152
|
+(
|
|
153
|
+ SELECT icp_id, COUNT(DISTINCT read_date) AS data_days
|
|
154
|
+ FROM coup_prd.coupdatamaster
|
|
155
|
+ WHERE read_date >= to_date('01/01/2017','dd/mm/yyyy')
|
|
156
|
+ AND read_date < to_date('01/01/2018','dd/mm/yyyy')
|
|
157
|
+ AND content_code = 'UN'
|
|
158
|
+ GROUP BY icp_id
|
|
159
|
+) AS cir
|
|
160
|
+WHERE data_days >= 360;
|