Revision 12923
Added by Aaron Marcuse-Kubitza almost 11 years ago
trunk/validation/aggregating/plots/SALVIAS/bien3_validations_salvias_db_original.VegCore.sql | ||
---|---|---|
12 | 12 |
-- ------------------ |
13 | 13 |
-- 1. Count of projects |
14 | 14 |
-- ------------------ |
15 |
CREATE OR REPLACE VIEW _plots_01_count_of_projects AS
|
|
15 |
CREATE VIEW _plots_01_count_of_projects AS |
|
16 | 16 |
SELECT COUNT(*) AS projects |
17 | 17 |
FROM projects |
18 | 18 |
; |
... | ... | |
20 | 20 |
-- ------------------ |
21 | 21 |
-- 2. List of project names |
22 | 22 |
-- ------------------ |
23 |
CREATE OR REPLACE VIEW _plots_02_list_of_project_names AS
|
|
23 |
CREATE VIEW _plots_02_list_of_project_names AS |
|
24 | 24 |
SELECT project_name AS projectname |
25 | 25 |
FROM projects |
26 | 26 |
; |
... | ... | |
28 | 28 |
-- ------------------ |
29 | 29 |
-- 3. Count of all plots in this source |
30 | 30 |
-- ------------------ |
31 |
CREATE OR REPLACE VIEW _plots_03_count_of_all_plots_in_this_source AS
|
|
31 |
CREATE VIEW _plots_03_count_of_all_plots_in_this_source AS |
|
32 | 32 |
SELECT COUNT(DISTINCT "SiteCode") AS plots |
33 | 33 |
FROM projects p JOIN "plotMetadata" pm |
34 | 34 |
ON p.project_id=pm.project_id |
... | ... | |
37 | 37 |
-- ------------------ |
38 | 38 |
-- 4. Count of plots in each project in this source |
39 | 39 |
-- ------------------ |
40 |
CREATE OR REPLACE VIEW _plots_04_count_of_plots_in_each_project_in_this_source AS
|
|
40 |
CREATE VIEW _plots_04_count_of_plots_in_each_project_in_this_source AS |
|
41 | 41 |
SELECT p.project_name, COUNT(*) AS plots |
42 | 42 |
FROM projects p JOIN "plotMetadata" pm |
43 | 43 |
ON p.project_id=pm.project_id |
... | ... | |
47 | 47 |
-- ------------------ |
48 | 48 |
-- 5.List of plot codes by project |
49 | 49 |
-- ------------------ |
50 |
CREATE OR REPLACE VIEW _plots_05_list_of_plot_codes_by_project AS
|
|
50 |
CREATE VIEW _plots_05_list_of_plot_codes_by_project AS |
|
51 | 51 |
SELECT p.project_name, pm."SiteCode" |
52 | 52 |
FROM projects p JOIN "plotMetadata" pm |
53 | 53 |
ON p.project_id=pm.project_id |
... | ... | |
56 | 56 |
-- ------------------ |
57 | 57 |
-- 6. List of plots with stem measurements |
58 | 58 |
-- ------------------ |
59 |
CREATE OR REPLACE VIEW _plots_06_list_of_plots_with_stem_measurements AS
|
|
59 |
CREATE VIEW _plots_06_list_of_plots_with_stem_measurements AS |
|
60 | 60 |
SELECT DISTINCT p.project_name, pm."SiteCode" |
61 | 61 |
FROM projects p |
62 | 62 |
JOIN "plotMetadata" pm ON p.project_id=pm.project_id |
... | ... | |
69 | 69 |
-- ------------------ |
70 | 70 |
-- 7.List of plots with counts of individuals per species |
71 | 71 |
-- ------------------ |
72 |
CREATE OR REPLACE VIEW _plots_07_list_of_plots_with_counts_of_individuals_per_species AS
|
|
72 |
CREATE VIEW _plots_07_list_of_plots_with_counts_of_individuals_per_species AS |
|
73 | 73 |
SELECT DISTINCT p.project_name, pm."SiteCode" |
74 | 74 |
FROM projects p |
75 | 75 |
JOIN "plotMetadata" pm ON p.project_id=pm.project_id |
... | ... | |
82 | 82 |
-- ------------------ |
83 | 83 |
-- 8.List of plots which use percent cover |
84 | 84 |
-- ------------------ |
85 |
CREATE OR REPLACE VIEW _plots_08_list_of_plots_which_use_percent_cover AS
|
|
85 |
CREATE VIEW _plots_08_list_of_plots_which_use_percent_cover AS |
|
86 | 86 |
SELECT DISTINCT p.project_name, pm."SiteCode" |
87 | 87 |
FROM projects p |
88 | 88 |
JOIN "plotMetadata" pm ON p.project_id=pm.project_id |
... | ... | |
95 | 95 |
-- ------------------ |
96 | 96 |
-- 9.List of plots which use line-intercept |
97 | 97 |
-- ------------------ |
98 |
CREATE OR REPLACE VIEW _plots_09_list_of_plots_which_use_line_intercept AS
|
|
98 |
CREATE VIEW _plots_09_list_of_plots_which_use_line_intercept AS |
|
99 | 99 |
SELECT DISTINCT p.project_name, pm."SiteCode" |
100 | 100 |
FROM projects p |
101 | 101 |
JOIN "plotMetadata" pm ON p.project_id=pm.project_id |
... | ... | |
115 | 115 |
-- incorrect total for plots such as Gentry plot, which count individuals |
116 | 116 |
-- per species per subplot |
117 | 117 |
-- ------------------ |
118 |
CREATE OR REPLACE VIEW _plots_10_count_of_individuals_per_plot_in_each_project AS
|
|
118 |
CREATE VIEW _plots_10_count_of_individuals_per_plot_in_each_project AS |
|
119 | 119 |
SELECT p.project_name, "SiteCode" AS plotcode, |
120 | 120 |
SUM("NoInd") AS individuals |
121 | 121 |
FROM projects p |
... | ... | |
130 | 130 |
-- |
131 | 131 |
-- Method: count records in stems table |
132 | 132 |
-- ------------------ |
133 |
CREATE OR REPLACE VIEW _plots_11_count_of_stems_per_plot_in_each_project AS
|
|
133 |
CREATE VIEW _plots_11_count_of_stems_per_plot_in_each_project AS |
|
134 | 134 |
SELECT p.project_name, "SiteCode" AS plotcode, |
135 | 135 |
COUNT(DISTINCT stem_id) AS stems |
136 | 136 |
FROM projects p |
... | ... | |
147 | 147 |
-- Note: Assumes identical concatenation of taxonomic fields |
148 | 148 |
-- to form verbatim taxon name in vegBIEN |
149 | 149 |
-- ------------------ |
150 |
CREATE OR REPLACE VIEW _plots_12_count_of_verbatim_taxa_per_plot_in_each_project AS
|
|
150 |
CREATE VIEW _plots_12_count_of_verbatim_taxa_per_plot_in_each_project AS |
|
151 | 151 |
SELECT project_name, plotcode, COUNT(taxon) AS taxa |
152 | 152 |
FROM |
153 | 153 |
( |
... | ... | |
170 | 170 |
-- Note: Assumes identical concatenation of taxonomic fields |
171 | 171 |
-- to form verbatim taxon name in vegBIEN. |
172 | 172 |
-- ------------------ |
173 |
CREATE OR REPLACE VIEW _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p AS
|
|
173 |
CREATE VIEW _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p AS |
|
174 | 174 |
SELECT DISTINCT p.project_name, "SiteCode" AS plotcode, |
175 | 175 |
TRIM(CONCAT_WS(' ',IFNULL("Family",''),IFNULL("Genus",''),IFNULL("Species",''), |
176 | 176 |
IF(infra_ep_1 IS NULL,IFNULL(auth,''), |
... | ... | |
188 | 188 |
-- Note: Assumes identical concatenation of taxonomic fields |
189 | 189 |
-- to form verbatim taxon name in vegBIEN |
190 | 190 |
-- ------------------ |
191 |
CREATE OR REPLACE VIEW _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr AS
|
|
191 |
CREATE VIEW _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr AS |
|
192 | 192 |
SELECT DISTINCT p.project_name, "SiteCode" AS plotcode, |
193 | 193 |
TRIM(CONCAT_WS(' ',IFNULL("Family",''),IFNULL("Genus",''),IFNULL("Species",''), |
194 | 194 |
IF(infra_ep_1 IS NULL,IFNULL(auth,''), |
... | ... | |
215 | 215 |
-- per species per plot) in same query. |
216 | 216 |
-- Note 3: currently, there are no SALVIAS percent cover plots in BIEN |
217 | 217 |
-- ------------------ |
218 |
CREATE OR REPLACE VIEW _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro AS
|
|
218 |
CREATE VIEW _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro AS |
|
219 | 219 |
SELECT DISTINCT p.project_name, "SiteCode" AS plotcode, |
220 | 220 |
TRIM(CONCAT_WS(' ',IFNULL("Family",''),IFNULL("Genus",''),IFNULL("Species",''), |
221 | 221 |
IF(infra_ep_1 IS NULL,IFNULL(auth,''), |
... | ... | |
242 | 242 |
-- stratum) with plots without subplots or strata (one cover measure |
243 | 243 |
-- per species per plot. |
244 | 244 |
-- ------------------ |
245 |
CREATE OR REPLACE VIEW _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj AS
|
|
245 |
CREATE VIEW _plots_16_intercepts_for_each_verb_taxon_in_each_plot_each_proj AS |
|
246 | 246 |
SELECT DISTINCT p.project_name, "SiteCode" AS plotcode, |
247 | 247 |
TRIM(CONCAT_WS(' ',IFNULL("Family",''),IFNULL("Genus",''),IFNULL("Species",''), |
248 | 248 |
IF(infra_ep_1 IS NULL,IFNULL(auth,''), |
... | ... | |
259 | 259 |
-- ------------------ |
260 | 260 |
-- 17. Count of subplots per plot, for each project |
261 | 261 |
-- ------------------ |
262 |
CREATE OR REPLACE VIEW _plots_17_count_of_subplots_per_plot_for_each_project AS
|
|
262 |
CREATE VIEW _plots_17_count_of_subplots_per_plot_for_each_project AS |
|
263 | 263 |
SELECT project_name, pm."SiteCode" AS plotcode, COUNT(DISTINCT "Line") as subplots |
264 | 264 |
FROM projects p |
265 | 265 |
JOIN "plotMetadata" pm ON p.project_id=pm.project_id |
... | ... | |
273 | 273 |
-- |
274 | 274 |
-- Note: includes plots with and without subplots |
275 | 275 |
-- ------------------ |
276 |
CREATE OR REPLACE VIEW _plots_18_list_of_subplots_codes_for_each_plot_for_each_project AS
|
|
276 |
CREATE VIEW _plots_18_list_of_subplots_codes_for_each_plot_for_each_project AS |
|
277 | 277 |
SELECT DISTINCT project_name, pm."SiteCode" AS plotcode, "Line" as subplot |
278 | 278 |
FROM projects p |
279 | 279 |
JOIN "plotMetadata" pm ON p.project_id=pm.project_id |
trunk/validation/aggregating/specimens/NY/qualitative_validations_source_db_NYBG.VegCore.sql | ||
---|---|---|
6 | 6 |
|
7 | 7 |
SET search_path TO "NY"; |
8 | 8 |
|
9 |
CREATE OR REPLACE VIEW _specimens_01_count_of_total_records_specimens_in_source_db AS
|
|
9 |
CREATE VIEW _specimens_01_count_of_total_records_specimens_in_source_db AS |
|
10 | 10 |
SELECT COUNT(*) "totalSpecimenRecords" |
11 | 11 |
FROM "Ecatalog_all"; |
12 | 12 |
COMMENT ON VIEW _specimens_01_count_of_total_records_specimens_in_source_db IS ' |
13 | 13 |
Check: should return 1 row |
14 | 14 |
'; |
15 | 15 |
|
16 |
CREATE OR REPLACE VIEW _specimens_02_count_of_unique_verbatim_families AS
|
|
16 |
CREATE VIEW _specimens_02_count_of_unique_verbatim_families AS |
|
17 | 17 |
SELECT COUNT(DISTINCT family) AS families FROM "Ecatalog_all" WHERE family IS NOT NULL; |
18 | 18 |
COMMENT ON VIEW _specimens_02_count_of_unique_verbatim_families IS ' |
19 | 19 |
Check: should return 1 row |
20 | 20 |
'; |
21 | 21 |
|
22 |
CREATE OR REPLACE VIEW _specimens_03_list_of_verbatim_families AS
|
|
22 |
CREATE VIEW _specimens_03_list_of_verbatim_families AS |
|
23 | 23 |
SELECT DISTINCT CONCAT_WS(' ', genus, "specificEpithet") AS "specificEpithet" |
24 | 24 |
FROM "Ecatalog_all" |
25 | 25 |
WHERE genus IS NOT NULL AND "specificEpithet" IS NOT NULL; |
... | ... | |
27 | 27 |
Check: should return same number of rows |
28 | 28 |
'; |
29 | 29 |
|
30 |
CREATE OR REPLACE VIEW _specimens_04_count_of_unique_verbatim_species_without_author AS
|
|
30 |
CREATE VIEW _specimens_04_count_of_unique_verbatim_species_without_author AS |
|
31 | 31 |
SELECT COUNT(DISTINCT CONCAT_WS(' ', genus, "specificEpithet")) AS subspecies FROM "Ecatalog_all" |
32 | 32 |
WHERE genus IS NOT NULL AND "specificEpithet" IS NOT NULL AND subspecies IS NOT NULL; |
33 | 33 |
COMMENT ON VIEW _specimens_04_count_of_unique_verbatim_species_without_author IS ' |
34 | 34 |
Check: should return 1 row |
35 | 35 |
'; |
36 | 36 |
|
37 |
CREATE OR REPLACE VIEW _specimens_05_list_of_verbatim_species_excluding_author AS
|
|
37 |
CREATE VIEW _specimens_05_list_of_verbatim_species_excluding_author AS |
|
38 | 38 |
SELECT DISTINCT CONCAT_WS(' ', genus, "specificEpithet") AS subspecies FROM "Ecatalog_all" |
39 | 39 |
WHERE genus IS NOT NULL AND "specificEpithet" IS NOT NULL AND subspecies IS NOT NULL; |
40 | 40 |
COMMENT ON VIEW _specimens_05_list_of_verbatim_species_excluding_author IS ' |
41 | 41 |
Check: should return 3335 rows |
42 | 42 |
'; |
43 | 43 |
|
44 |
CREATE OR REPLACE VIEW _specimens_06_count_of_unique_verb_subsp_taxa_without_author AS
|
|
44 |
CREATE VIEW _specimens_06_count_of_unique_verb_subsp_taxa_without_author AS |
|
45 | 45 |
SELECT COUNT(DISTINCT CONCAT_WS(' ', genus, "specificEpithet", subspecies)) AS "specificEpithet" FROM "Ecatalog_all" |
46 | 46 |
WHERE genus IS NOT NULL AND "specificEpithet" IS NOT NULL; |
47 | 47 |
COMMENT ON VIEW _specimens_06_count_of_unique_verb_subsp_taxa_without_author IS ' |
48 | 48 |
Check: should return 1 row |
49 | 49 |
'; |
50 | 50 |
|
51 |
CREATE OR REPLACE VIEW _specimens_07_list_of_verbatim_subspecific_taxa_without_author AS
|
|
51 |
CREATE VIEW _specimens_07_list_of_verbatim_subspecific_taxa_without_author AS |
|
52 | 52 |
SELECT DISTINCT CONCAT_WS(' ', genus, "specificEpithet") AS "specificEpithet" |
53 | 53 |
FROM "Ecatalog_all" |
54 | 54 |
WHERE genus IS NOT NULL AND "specificEpithet" IS NOT NULL; |
... | ... | |
56 | 56 |
Check: should return 40145 rows |
57 | 57 |
'; |
58 | 58 |
|
59 |
CREATE OR REPLACE VIEW _specimens_08_count_of_unique_verbatim_author_taxa_with_genus AS
|
|
59 |
CREATE VIEW _specimens_08_count_of_unique_verbatim_author_taxa_with_genus AS |
|
60 | 60 |
SELECT COUNT(DISTINCT TRIM(CONCAT_WS(' ', |
61 | 61 |
TRIM(CONCAT_WS(' ', genus, IFNULL("specificEpithet",''), IFNULL(subspecies,''))), |
62 | 62 |
TRIM(IFNULL("scientificNameAuthorship",'')) |
... | ... | |
67 | 67 |
Check: should return 1 row |
68 | 68 |
'; |
69 | 69 |
|
70 |
CREATE OR REPLACE VIEW _specimens_09_list_of_unique_verbatim_author_taxa_with_genus AS
|
|
70 |
CREATE VIEW _specimens_09_list_of_unique_verbatim_author_taxa_with_genus AS |
|
71 | 71 |
SELECT DISTINCT TRIM(CONCAT_WS(' ', |
72 | 72 |
TRIM(CONCAT_WS(' ', genus, IFNULL("specificEpithet",''), IFNULL(subspecies,''))), |
73 | 73 |
TRIM(IFNULL("scientificNameAuthorship",'')) |
... | ... | |
78 | 78 |
Check: should return 45997 rows |
79 | 79 |
'; |
80 | 80 |
|
81 |
CREATE OR REPLACE VIEW _specimens_10_count_number_of_records_by_institution AS
|
|
81 |
CREATE VIEW _specimens_10_count_number_of_records_by_institution AS |
|
82 | 82 |
SELECT specimen_duplicate_institutions, COUNT(*) AS records |
83 | 83 |
FROM "Ecatalog_all" |
84 | 84 |
GROUP BY specimen_duplicate_institutions; |
... | ... | |
88 | 88 |
Check: should return 6 rows |
89 | 89 |
'; |
90 | 90 |
|
91 |
CREATE OR REPLACE VIEW _specimens_11_list_of_three_standard_political_divisions AS
|
|
91 |
CREATE VIEW _specimens_11_list_of_three_standard_political_divisions AS |
|
92 | 92 |
SELECT DISTINCT country, "stateProvince", county |
93 | 93 |
FROM "Ecatalog_all"; |
94 | 94 |
COMMENT ON VIEW _specimens_11_list_of_three_standard_political_divisions IS ' |
... | ... | |
97 | 97 |
Check: should return 5232 rows |
98 | 98 |
'; |
99 | 99 |
|
100 |
CREATE OR REPLACE VIEW _specimens_12_distinct_collector_name_collect_num_date_w_count AS
|
|
100 |
CREATE VIEW _specimens_12_distinct_collector_name_collect_num_date_w_count AS |
|
101 | 101 |
SELECT IFNULL("recordedBy",'') AS "collectorName", IFNULL("collectorNumber",'') AS "collectionNumber", |
102 | 102 |
CONCAT_WS('-', "yearCollected", "monthCollected", "dayCollected") AS "dateCollected", COUNT(*) AS "specimenRecords" |
103 | 103 |
FROM "Ecatalog_all" |
... | ... | |
107 | 107 |
Check: should return 309396 rows |
108 | 108 |
'; |
109 | 109 |
|
110 |
CREATE OR REPLACE VIEW _specimens_13_count_of_all_verbatim_and_decimal_lat_long AS
|
|
110 |
CREATE VIEW _specimens_13_count_of_all_verbatim_and_decimal_lat_long AS |
|
111 | 111 |
SELECT |
112 | 112 |
( |
113 | 113 |
SELECT COUNT(*) |
... | ... | |
133 | 133 |
Check: should return 1 row |
134 | 134 |
'; |
135 | 135 |
|
136 |
CREATE OR REPLACE VIEW _specimens_14_count_of_all_invalid_verbatim_lat_long AS
|
|
136 |
CREATE VIEW _specimens_14_count_of_all_invalid_verbatim_lat_long AS |
|
137 | 137 |
SELECT |
138 | 138 |
( |
139 | 139 |
SELECT COUNT(*) |
... | ... | |
149 | 149 |
Check: should return 1 row |
150 | 150 |
'; |
151 | 151 |
|
152 |
CREATE OR REPLACE VIEW _specimens_15_list_distinct_locality_descriptions AS
|
|
152 |
CREATE VIEW _specimens_15_list_distinct_locality_descriptions AS |
|
153 | 153 |
SELECT DISTINCT locality__main AS "localityDescription" |
154 | 154 |
FROM "Ecatalog_all" |
155 | 155 |
WHERE locality__main IS NOT NULL; |
... | ... | |
157 | 157 |
Check: should return 125592 records |
158 | 158 |
'; |
159 | 159 |
|
160 |
CREATE OR REPLACE VIEW _specimens_16_list_distinct_specimen_descriptions AS
|
|
160 |
CREATE VIEW _specimens_16_list_distinct_specimen_descriptions AS |
|
161 | 161 |
SELECT "specimenDescription" AS "specimenDescription" |
162 | 162 |
FROM "Ecatalog_all" |
163 | 163 |
WHERE "specimenDescription" IS NOT NULL; |
trunk/validation/aggregating/specimens/qualitative_validations_specimens.sql | ||
---|---|---|
9 | 9 |
|
10 | 10 |
SET search_path TO public_validations, public; |
11 | 11 |
|
12 |
CREATE OR REPLACE VIEW _specimens_01_count_of_total_records_specimens_in_source_db AS
|
|
12 |
CREATE VIEW _specimens_01_count_of_total_records_specimens_in_source_db AS |
|
13 | 13 |
; |
14 | 14 |
|
15 |
CREATE OR REPLACE VIEW _specimens_02_count_of_unique_verbatim_families AS
|
|
15 |
CREATE VIEW _specimens_02_count_of_unique_verbatim_families AS |
|
16 | 16 |
; |
17 | 17 |
|
18 |
CREATE OR REPLACE VIEW _specimens_03_list_of_verbatim_families AS
|
|
18 |
CREATE VIEW _specimens_03_list_of_verbatim_families AS |
|
19 | 19 |
; |
20 | 20 |
|
21 |
CREATE OR REPLACE VIEW _specimens_04_count_of_unique_verbatim_species_without_author AS
|
|
21 |
CREATE VIEW _specimens_04_count_of_unique_verbatim_species_without_author AS |
|
22 | 22 |
; |
23 | 23 |
|
24 |
CREATE OR REPLACE VIEW _specimens_05_list_of_verbatim_species_excluding_author AS
|
|
24 |
CREATE VIEW _specimens_05_list_of_verbatim_species_excluding_author AS |
|
25 | 25 |
; |
26 | 26 |
|
27 |
CREATE OR REPLACE VIEW _specimens_06_count_of_unique_verb_subsp_taxa_without_author AS
|
|
27 |
CREATE VIEW _specimens_06_count_of_unique_verb_subsp_taxa_without_author AS |
|
28 | 28 |
; |
29 | 29 |
|
30 |
CREATE OR REPLACE VIEW _specimens_07_list_of_verbatim_subspecific_taxa_without_author AS
|
|
30 |
CREATE VIEW _specimens_07_list_of_verbatim_subspecific_taxa_without_author AS |
|
31 | 31 |
; |
32 | 32 |
|
33 |
CREATE OR REPLACE VIEW _specimens_08_count_of_unique_verbatim_author_taxa_with_genus AS
|
|
33 |
CREATE VIEW _specimens_08_count_of_unique_verbatim_author_taxa_with_genus AS |
|
34 | 34 |
; |
35 | 35 |
|
36 |
CREATE OR REPLACE VIEW _specimens_09_list_of_unique_verbatim_author_taxa_with_genus AS
|
|
36 |
CREATE VIEW _specimens_09_list_of_unique_verbatim_author_taxa_with_genus AS |
|
37 | 37 |
; |
38 | 38 |
|
39 |
CREATE OR REPLACE VIEW _specimens_10_count_number_of_records_by_institution AS
|
|
39 |
CREATE VIEW _specimens_10_count_number_of_records_by_institution AS |
|
40 | 40 |
; |
41 | 41 |
|
42 |
CREATE OR REPLACE VIEW _specimens_11_list_of_three_standard_political_divisions AS
|
|
42 |
CREATE VIEW _specimens_11_list_of_three_standard_political_divisions AS |
|
43 | 43 |
; |
44 | 44 |
COMMENT ON VIEW _specimens_01_count_of_total_records_specimens_in_source_db |
45 | 45 |
IS ' |
46 | 46 |
Note: character set issues may cause mis-matches. This query is a good way to reveal character set issues, either in source db or in BIEN |
47 | 47 |
'; |
48 | 48 |
|
49 |
CREATE OR REPLACE VIEW _specimens_12_distinct_collector_name_collect_num_date_w_count AS
|
|
49 |
CREATE VIEW _specimens_12_distinct_collector_name_collect_num_date_w_count AS |
|
50 | 50 |
; |
51 | 51 |
|
52 |
CREATE OR REPLACE VIEW _specimens_13_count_of_all_verbatim_and_decimal_lat_long AS
|
|
52 |
CREATE VIEW _specimens_13_count_of_all_verbatim_and_decimal_lat_long AS |
|
53 | 53 |
; |
54 | 54 |
|
55 |
CREATE OR REPLACE VIEW _specimens_14_count_of_all_invalid_verbatim_lat_long AS
|
|
55 |
CREATE VIEW _specimens_14_count_of_all_invalid_verbatim_lat_long AS |
|
56 | 56 |
; |
57 | 57 |
|
58 |
CREATE OR REPLACE VIEW _specimens_15_list_distinct_locality_descriptions AS
|
|
58 |
CREATE VIEW _specimens_15_list_distinct_locality_descriptions AS |
|
59 | 59 |
; |
60 | 60 |
|
61 |
CREATE OR REPLACE VIEW _specimens_16_list_distinct_specimen_descriptions AS
|
|
61 |
CREATE VIEW _specimens_16_list_distinct_specimen_descriptions AS |
|
62 | 62 |
; |
trunk/validation/aggregating/traits/bien3_validations_traits_bien3.sql | ||
---|---|---|
10 | 10 |
-- ------------------ |
11 | 11 |
-- 1. Count records |
12 | 12 |
-- ------------------ |
13 |
CREATE OR REPLACE VIEW _traits_01_count_records AS
|
|
13 |
CREATE VIEW _traits_01_count_records AS |
|
14 | 14 |
SELECT COUNT(*) AS "totalRecords" |
15 | 15 |
FROM trait |
16 | 16 |
JOIN taxonoccurrence USING (taxonoccurrence_id) |
... | ... | |
20 | 20 |
-- ------------------ |
21 | 21 |
-- 2. Count trait names |
22 | 22 |
-- ------------------ |
23 |
CREATE OR REPLACE VIEW _traits_02_count_trait_names AS
|
|
23 |
CREATE VIEW _traits_02_count_trait_names AS |
|
24 | 24 |
SELECT COUNT(DISTINCT name) AS traits |
25 | 25 |
FROM trait |
26 | 26 |
JOIN taxonoccurrence USING (taxonoccurrence_id) |
... | ... | |
29 | 29 |
-- ------------------ |
30 | 30 |
-- 3. List trait names |
31 | 31 |
-- ------------------ |
32 |
CREATE OR REPLACE VIEW _traits_03_list_trait_names AS
|
|
32 |
CREATE VIEW _traits_03_list_trait_names AS |
|
33 | 33 |
SELECT DISTINCT name AS trait |
34 | 34 |
FROM trait |
35 | 35 |
JOIN taxonoccurrence USING (taxonoccurrence_id) |
... | ... | |
40 | 40 |
-- ------------------ |
41 | 41 |
-- 4. Count records per trait |
42 | 42 |
-- ------------------ |
43 |
CREATE OR REPLACE VIEW _traits_04_count_records_per_trait AS
|
|
43 |
CREATE VIEW _traits_04_count_records_per_trait AS |
|
44 | 44 |
SELECT name AS trait, COUNT(*) AS measurements |
45 | 45 |
FROM trait |
46 | 46 |
JOIN taxonoccurrence USING (taxonoccurrence_id) |
... | ... | |
55 | 55 |
-- Note: No morphospecies in trait table, therefore count |
56 | 56 |
-- taxon + authority only |
57 | 57 |
-- ------------------ |
58 |
CREATE OR REPLACE VIEW _traits_05_count_taxa AS
|
|
58 |
CREATE VIEW _traits_05_count_taxa AS |
|
59 | 59 |
SELECT COUNT(DISTINCT (taxonname, author)) AS taxa |
60 | 60 |
FROM taxonverbatim |
61 | 61 |
WHERE source_id = (SELECT source_by_shortname(current_schema)) |
... | ... | |
68 | 68 |
-- Note 2: Note formation of taxonCorrected: includes family ONLY if |
69 | 69 |
-- taxon is not determined at least to genus |
70 | 70 |
-- ------------------ |
71 |
CREATE OR REPLACE VIEW _traits_06_list_taxa AS
|
|
71 |
CREATE VIEW _traits_06_list_taxa AS |
|
72 | 72 |
SELECT DISTINCT concat_ws(' ', taxonname, author) AS taxonwithauthor |
73 | 73 |
FROM taxonverbatim |
74 | 74 |
WHERE source_id = (SELECT source_by_shortname(current_schema)) |
... | ... | |
78 | 78 |
-- ------------------ |
79 | 79 |
-- 7. Trait, value and units for first 5000 records |
80 | 80 |
-- ------------------ |
81 |
CREATE OR REPLACE VIEW _traits_07_trait_value_and_units_for_first_5000_records AS
|
|
81 |
CREATE VIEW _traits_07_trait_value_and_units_for_first_5000_records AS |
|
82 | 82 |
SELECT name AS trait, value, units |
83 | 83 |
FROM trait |
84 | 84 |
JOIN taxonoccurrence USING (taxonoccurrence_id) |
... | ... | |
90 | 90 |
-- ------------------ |
91 | 91 |
-- 8. Taxon, trait and value for first 5000 records |
92 | 92 |
-- ------------------ |
93 |
CREATE OR REPLACE VIEW _traits_08_taxon_trait_and_value_for_first_5000_records AS
|
|
93 |
CREATE VIEW _traits_08_taxon_trait_and_value_for_first_5000_records AS |
|
94 | 94 |
SELECT concat_ws(' ', taxonname, author) AS taxonwithauthor, name AS trait, value |
95 | 95 |
FROM taxonverbatim |
96 | 96 |
JOIN taxondetermination ON taxondetermination.taxonverbatim_id = taxonverbatim.taxonverbatim_id AND taxondetermination.iscurrent |
trunk/validation/aggregating/traits/BIEN2_traits/bien3_validations_traits_original_mysql.VegCore.sql | ||
---|---|---|
10 | 10 |
-- ------------------ |
11 | 11 |
-- 1. Count records |
12 | 12 |
-- ------------------ |
13 |
CREATE OR REPLACE VIEW _traits_01_count_records AS
|
|
13 |
CREATE VIEW _traits_01_count_records AS |
|
14 | 14 |
SELECT COUNT(*) AS totalrecords |
15 | 15 |
FROM "TraitObservation" |
16 | 16 |
WHERE "taxonName" IS NOT NULL AND "taxonName"<>'' AND "measurementName" IS NOT NULL AND "measurementName"<>'' |
... | ... | |
19 | 19 |
-- ------------------ |
20 | 20 |
-- 2. Count trait names |
21 | 21 |
-- ------------------ |
22 |
CREATE OR REPLACE VIEW _traits_02_count_trait_names AS
|
|
22 |
CREATE VIEW _traits_02_count_trait_names AS |
|
23 | 23 |
SELECT COUNT(DISTINCT "measurementName") AS traits |
24 | 24 |
FROM "TraitObservation" |
25 | 25 |
WHERE "taxonName" IS NOT NULL AND "taxonName"<>'' AND "measurementName" IS NOT NULL AND "measurementName"<>'' |
... | ... | |
28 | 28 |
-- ------------------ |
29 | 29 |
-- 3. List trait names |
30 | 30 |
-- ------------------ |
31 |
CREATE OR REPLACE VIEW _traits_03_list_trait_names AS
|
|
31 |
CREATE VIEW _traits_03_list_trait_names AS |
|
32 | 32 |
SELECT DISTINCT "measurementName" AS trait |
33 | 33 |
FROM "TraitObservation" |
34 | 34 |
WHERE "taxonName" IS NOT NULL AND "taxonName"<>'' AND "measurementName" IS NOT NULL AND "measurementName"<>'' |
... | ... | |
38 | 38 |
-- ------------------ |
39 | 39 |
-- 4. Count records per trait |
40 | 40 |
-- ------------------ |
41 |
CREATE OR REPLACE VIEW _traits_04_count_records_per_trait AS
|
|
41 |
CREATE VIEW _traits_04_count_records_per_trait AS |
|
42 | 42 |
SELECT "measurementName" AS trait, COUNT(*) AS measurements |
43 | 43 |
FROM "TraitObservation" |
44 | 44 |
WHERE "taxonName" IS NOT NULL AND "taxonName"<>'' AND "measurementName" IS NOT NULL AND "measurementName"<>'' |
... | ... | |
49 | 49 |
-- ------------------ |
50 | 50 |
-- 5. Count taxa |
51 | 51 |
-- ------------------ |
52 |
CREATE OR REPLACE VIEW _traits_05_count_taxa AS
|
|
52 |
CREATE VIEW _traits_05_count_taxa AS |
|
53 | 53 |
SELECT COUNT(DISTINCT |
54 | 54 |
TRIM(CONCAT_WS(' ',IFNULL("taxonName",''),IFNULL("scientificNameAuthorship",''))) |
55 | 55 |
) AS taxa |
... | ... | |
60 | 60 |
-- ------------------ |
61 | 61 |
-- 6. List distinct taxa |
62 | 62 |
-- ------------------ |
63 |
CREATE OR REPLACE VIEW _traits_06_list_distinct_taxa AS
|
|
63 |
CREATE VIEW _traits_06_list_distinct_taxa AS |
|
64 | 64 |
SELECT DISTINCT |
65 | 65 |
TRIM(CONCAT_WS(' ',IFNULL("taxonName",''),IFNULL("scientificNameAuthorship",''))) |
66 | 66 |
AS taxonwithauthor |
... | ... | |
72 | 72 |
-- ------------------ |
73 | 73 |
-- 7. Trait, value and units |
74 | 74 |
-- ------------------ |
75 |
CREATE OR REPLACE VIEW _traits_07_trait_value_and_units AS
|
|
75 |
CREATE VIEW _traits_07_trait_value_and_units AS |
|
76 | 76 |
SELECT "measurementName" AS trait, "measurementValue" AS value, "measurementUnit" AS units |
77 | 77 |
FROM "TraitObservation" |
78 | 78 |
WHERE "taxonName" IS NOT NULL AND "taxonName"<>'' AND "measurementName" IS NOT NULL AND "measurementName"<>'' |
... | ... | |
82 | 82 |
-- ------------------ |
83 | 83 |
-- 8. "taxonName", trait and value for first 5000 records |
84 | 84 |
-- ------------------ |
85 |
CREATE OR REPLACE VIEW _traits_08_taxonname_trait_and_value_for_first_5000_records AS
|
|
85 |
CREATE VIEW _traits_08_taxonname_trait_and_value_for_first_5000_records AS |
|
86 | 86 |
SELECT |
87 | 87 |
TRIM(CONCAT_WS(' ',IFNULL("taxonName",''),IFNULL("scientificNameAuthorship",''))) |
88 | 88 |
AS taxonwithauthor, |
Also available in: Unified diff
validation/**.sql: replaced CREATE OR REPLACE VIEW with CREATE VIEW to match pg_dump output for diffing