|
16 | 16 |
|
17 | 17 | query_template = """ |
18 | 18 | SELECT {fields} |
19 | | - data_files.program_type, |
20 | 19 | data_files.section, |
21 | 20 | data_files.version, |
22 | 21 | data_files.year, |
23 | 22 | data_files.quarter, |
24 | 23 | stt.name AS "STT", -- Select stt_name from the stts table |
25 | 24 | stt.stt_code AS "STT_CODE", -- Select stt_code from the stts table |
26 | | - stt.region_id AS "REGION" -- Select region from the stts table |
| 25 | + stt.region_id AS "REGION", -- Select region from the stts table |
| 26 | + data_files.program_type |
27 | 27 | FROM {table} {record_type} |
28 | 28 | INNER JOIN |
29 | 29 | data_files_datafile data_files -- Join with data_files_datafile |
|
34 | 34 | section, -- Select section |
35 | 35 | year, -- Select fiscal_year |
36 | 36 | quarter, -- Select fiscal_quarter |
37 | | - MAX(version) AS version -- Get the maximum version for each group |
| 37 | + MAX(version) AS version, -- Get the maximum version for each group |
| 38 | + program_type -- Select program_type |
38 | 39 | FROM |
39 | 40 | data_files_datafile -- Subquery table |
40 | 41 | GROUP BY |
41 | | - stt_id, section, year, quarter -- Group by columns |
| 42 | + stt_id, program_type, section, year, quarter -- Group by columns |
42 | 43 | ) most_recent |
43 | 44 | ON data_files.stt_id = most_recent.stt_id |
44 | | - AND data_files.program_type = most_recent.program_type, |
45 | 45 | AND data_files.section = most_recent.section |
46 | 46 | AND data_files.version = most_recent.version |
47 | 47 | AND data_files.year = most_recent.year |
48 | 48 | AND data_files.quarter = most_recent.quarter |
| 49 | + AND data_files.program_type = most_recent.program_type |
49 | 50 | INNER JOIN |
50 | 51 | stts_stt stt -- Join with the stts table (aliased as stt) |
51 | 52 | ON data_files.stt_id = stt.id -- Join condition to match stt_id |
|
0 commit comments