You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Insert unique rows from `fluview_clinical` into `fluview_clinical_v2`.
27
+
-- This is done in order to reset ID counter and fill gaps betwen row's ids.
28
+
INSERT INTO
29
+
fluview_clinical_v2(
30
+
`release_date`,
31
+
`issue`,
32
+
`epiweek`,
33
+
`region`,
34
+
`lag`,
35
+
`total_specimens`,
36
+
`total_a`,
37
+
`total_b`,
38
+
`percent_positive`,
39
+
`percent_a`,
40
+
`percent_b`
41
+
)
42
+
SELECT
43
+
min_release_date release_date,
44
+
tmp.issue,
45
+
tmp.epiweek,
46
+
tmp.region,
47
+
tmp.lag,
48
+
tmp.total_specimens,
49
+
tmp.total_a,
50
+
tmp.total_b,
51
+
tmp.percent_positive,
52
+
tmp.percent_a,
53
+
tmp.percent_b
54
+
FROM
55
+
(
56
+
-- get data associated with the most recent `release_date` for each unique `(epiweek, issue, region)` key
57
+
SELECT
58
+
s.release_date,
59
+
s.issue,
60
+
s.epiweek,
61
+
s.region,
62
+
s.lag,
63
+
s.total_specimens,
64
+
s.total_a,
65
+
s.total_b,
66
+
s.percent_positive,
67
+
s.percent_a,
68
+
s.percent_b
69
+
FROM
70
+
(
71
+
SELECT
72
+
fc.release_date,
73
+
fc.issue,
74
+
fc.epiweek,
75
+
fc.region,
76
+
fc.lag,
77
+
fc.total_specimens,
78
+
fc.total_a,
79
+
fc.total_b,
80
+
fc.percent_positive,
81
+
fc.percent_a,
82
+
fc.percent_b,
83
+
ROW_NUMBER() OVER(
84
+
PARTITION BY fc.epiweek,
85
+
fc.issue,
86
+
fc.region
87
+
ORDER BY
88
+
fc.release_dateDESC
89
+
) as row_num
90
+
FROM
91
+
fluview_clinical fc
92
+
) s
93
+
WHERE
94
+
s.row_num=1
95
+
) tmp
96
+
JOIN (
97
+
-- JOIN to recover first/least `release_date` because thats what the acquisition process does: https://github.com/cmu-delphi/delphi-epidata/blob/7fd20cd5c34b33c2310be67867b46a91aa840be9/src/acquisition/fluview/fluview_update.py#L326
0 commit comments