1
|
-- -----------------------------------------------------------------------------
|
2
|
-- Quantitative validation queries on the BIEN database
|
3
|
--
|
4
|
-- Applies to SALVIAS, or any datasource with all of the following attributes:
|
5
|
-- - Plots
|
6
|
-- - Comprised of multiple datasets organized as "projects"
|
7
|
-- - Maximum 2-level nesting (subplots within plots)
|
8
|
-- - One or more plots contain individual observations with stem measurements
|
9
|
-- - One or more plots contain aggregate observations of counts of individuals within species
|
10
|
-- - One or more plots contain aggregate observations of cover by species
|
11
|
--
|
12
|
-- Requires list of projects from source db manager, in three groups: (1) individual observation
|
13
|
-- plot, (2) aggregate individual count plots, (3) aggregate percent cover plots
|
14
|
-- -------------------------------------------------------------------------
|
15
|
|
16
|
-- ------------------
|
17
|
-- Set variables specific to this source
|
18
|
-- Currently configured for SALVIAS
|
19
|
-- ------------------
|
20
|
\set datasource '''SALVIAS'''
|
21
|
|
22
|
SET enable_seqscan = off;
|
23
|
SET join_collapse_limit = 1; -- turn it off
|
24
|
|
25
|
-- _plots_01_count_of_projects
|
26
|
SELECT count(*) AS projects
|
27
|
FROM (project p
|
28
|
JOIN source s ON ((p.source_id = s.source_id)))
|
29
|
WHERE (s.shortname = :datasource::text);
|
30
|
|
31
|
-- _plots_02_list_of_project_names
|
32
|
SELECT p.projectname AS project_name
|
33
|
FROM (project p
|
34
|
JOIN source s ON ((p.source_id = s.source_id)))
|
35
|
WHERE (s.shortname = :datasource::text);
|
36
|
|
37
|
-- _plots_03_count_of_all_plots_in_this_source
|
38
|
SELECT count(*) AS plots
|
39
|
FROM (((plot l
|
40
|
JOIN locationevent le ON ((l.plot_id = le.location_id)))
|
41
|
JOIN project p ON ((p.project_id = le.project_id)))
|
42
|
JOIN source s ON ((p.source_id = s.source_id)))
|
43
|
WHERE (s.shortname = :datasource::text);
|
44
|
|
45
|
-- _plots_04_count_of_plots_in_each_project_in_this_source
|
46
|
SELECT p.projectname AS project_name,
|
47
|
count(DISTINCT l.plot_id) AS plots
|
48
|
FROM (((plot l
|
49
|
JOIN locationevent le ON ((l.plot_id = le.location_id)))
|
50
|
JOIN project p ON ((p.project_id = le.project_id)))
|
51
|
JOIN source s ON ((p.source_id = s.source_id)))
|
52
|
WHERE (s.shortname = :datasource::text)
|
53
|
GROUP BY p.projectname;
|
54
|
|
55
|
-- _plots_05_list_of_plot_codes_by_project
|
56
|
SELECT p.projectname AS project_name,
|
57
|
l.authorlocationcode AS plot_code
|
58
|
FROM (((plot l
|
59
|
JOIN locationevent le ON ((l.plot_id = le.location_id)))
|
60
|
JOIN project p ON ((p.project_id = le.project_id)))
|
61
|
JOIN source s ON ((p.source_id = s.source_id)))
|
62
|
WHERE (s.shortname = :datasource::text);
|
63
|
|
64
|
-- _plots_06_list_of_plots_with_stem_measurements
|
65
|
SELECT project.projectname AS project_name,
|
66
|
plot.authorlocationcode AS plot_code
|
67
|
FROM ((plot
|
68
|
JOIN locationevent USING (plot_id))
|
69
|
LEFT JOIN project USING (project_id))
|
70
|
WHERE ((plot.source_id = ( SELECT source_by_shortname(:datasource::text) AS source_by_shortname)) AND (EXISTS ( SELECT NULL::unknown AS unknown
|
71
|
FROM ((((locationevent locationevent_1
|
72
|
JOIN taxonoccurrence USING (locationevent_id))
|
73
|
JOIN aggregateoccurrence USING (taxonoccurrence_id))
|
74
|
JOIN plantobservation USING (aggregateoccurrence_id))
|
75
|
JOIN stemobservation USING (plantobservation_id))
|
76
|
WHERE ((locationevent_1.plot_id = plot.plot_id) AND ((stemobservation.sourceaccessioncode IS NOT NULL) OR (stemobservation.authorstemcode IS NOT NULL)))
|
77
|
LIMIT 1)))
|
78
|
ORDER BY plot.authorlocationcode;
|
79
|
|
80
|
-- _plots_06a_list_of_stems
|
81
|
SELECT project.projectname AS project_name,
|
82
|
plot.authorlocationcode AS plot_code,
|
83
|
stemobservation.sourceaccessioncode AS stem_id
|
84
|
FROM ((((((plot
|
85
|
JOIN locationevent USING (plot_id))
|
86
|
LEFT JOIN project USING (project_id))
|
87
|
JOIN taxonoccurrence USING (locationevent_id))
|
88
|
JOIN aggregateoccurrence USING (taxonoccurrence_id))
|
89
|
JOIN plantobservation USING (aggregateoccurrence_id))
|
90
|
JOIN stemobservation USING (plantobservation_id))
|
91
|
WHERE ((plot.source_id = ( SELECT source_by_shortname(:datasource::text) AS source_by_shortname)) AND ((stemobservation.sourceaccessioncode IS NOT NULL) OR (stemobservation.authorstemcode IS NOT NULL)))
|
92
|
ORDER BY project.projectname, plot.authorlocationcode, stemobservation.sourceaccessioncode;
|
93
|
|
94
|
-- _plots_07_list_of_plots_which_use_counts_of_indiv_per_species
|
95
|
SELECT project.projectname AS project_name,
|
96
|
plot.authorlocationcode AS plot_code
|
97
|
FROM ((plot
|
98
|
JOIN locationevent USING (plot_id))
|
99
|
LEFT JOIN project USING (project_id))
|
100
|
WHERE ((plot.source_id = ( SELECT source_by_shortname(:datasource::text) AS source_by_shortname)) AND (EXISTS ( SELECT NULL::unknown AS unknown
|
101
|
FROM ((locationevent locationevent_1
|
102
|
JOIN taxonoccurrence USING (locationevent_id))
|
103
|
JOIN aggregateoccurrence USING (taxonoccurrence_id))
|
104
|
WHERE ((locationevent_1.plot_id = plot.plot_id) AND (aggregateoccurrence.count > 1))
|
105
|
LIMIT 1)))
|
106
|
ORDER BY plot.authorlocationcode;
|
107
|
|
108
|
-- _plots_08_list_of_plots_which_use_percent_cover
|
109
|
SELECT project.projectname AS project_name,
|
110
|
plot.authorlocationcode AS plot_code
|
111
|
FROM ((plot
|
112
|
JOIN locationevent USING (plot_id))
|
113
|
LEFT JOIN project USING (project_id))
|
114
|
WHERE ((plot.source_id = ( SELECT source_by_shortname(:datasource::text) AS source_by_shortname)) AND (EXISTS ( SELECT NULL::unknown AS unknown
|
115
|
FROM ((locationevent locationevent_1
|
116
|
JOIN taxonoccurrence USING (locationevent_id))
|
117
|
JOIN aggregateoccurrence USING (taxonoccurrence_id))
|
118
|
WHERE ((locationevent_1.plot_id = plot.plot_id) AND (aggregateoccurrence.cover_fraction IS NOT NULL))
|
119
|
LIMIT 1)))
|
120
|
ORDER BY plot.authorlocationcode;
|
121
|
|
122
|
-- _plots_09_list_of_plots_which_use_line_intercept
|
123
|
SELECT project.projectname AS project_name,
|
124
|
plot.authorlocationcode AS plot_code
|
125
|
FROM ((plot
|
126
|
JOIN locationevent USING (plot_id))
|
127
|
LEFT JOIN project USING (project_id))
|
128
|
WHERE ((plot.source_id = ( SELECT source_by_shortname(:datasource::text) AS source_by_shortname)) AND (EXISTS ( SELECT NULL::unknown AS unknown
|
129
|
FROM ((locationevent locationevent_1
|
130
|
JOIN taxonoccurrence USING (locationevent_id))
|
131
|
JOIN aggregateoccurrence USING (taxonoccurrence_id))
|
132
|
WHERE ((locationevent_1.plot_id = plot.plot_id) AND (aggregateoccurrence.linecover_m IS NOT NULL))
|
133
|
LIMIT 1)))
|
134
|
ORDER BY plot.authorlocationcode;
|
135
|
|
136
|
-- _plots_10_count_of_individuals_per_plot_in_each_project
|
137
|
SELECT p.projectname AS project_name,
|
138
|
l.authorlocationcode AS plot_code,
|
139
|
sum(ao.count) AS individuals
|
140
|
FROM ((((((project p
|
141
|
JOIN source s ON ((p.source_id = s.source_id)))
|
142
|
JOIN place_visit ON ((p.project_id = place_visit.project_id)))
|
143
|
JOIN locationevent le ON ((place_visit.locationevent_id = le.place_visit_id)))
|
144
|
JOIN plot l ON ((place_visit.location_id = l.plot_id)))
|
145
|
JOIN taxonoccurrence o ON ((le.locationevent_id = o.locationevent_id)))
|
146
|
JOIN aggregateoccurrence ao ON ((o.taxonoccurrence_id = ao.taxonoccurrence_id)))
|
147
|
WHERE (s.shortname = :datasource::text)
|
148
|
GROUP BY p.projectname, l.authorlocationcode
|
149
|
ORDER BY p.projectname, l.authorlocationcode;
|
150
|
/*
|
151
|
Method: count taxonObservations
|
152
|
Note 1: `individuals` should be NULL for plots which use percent cover or line-intercept methods.
|
153
|
Note 2: Does this method requires that plots have 2-level nesting of subplots within plots?
|
154
|
*/
|
155
|
|
156
|
-- _plots_10a_aggregate_observation_individual_counts
|
157
|
SELECT p.projectname AS project_name,
|
158
|
l.authorlocationcode AS plot_code,
|
159
|
o.sourceaccessioncode AS individual_id,
|
160
|
ao.count AS individuals
|
161
|
FROM ((((((project p
|
162
|
JOIN source s ON ((p.source_id = s.source_id)))
|
163
|
JOIN place_visit ON ((p.project_id = place_visit.project_id)))
|
164
|
JOIN locationevent le ON ((place_visit.locationevent_id = le.place_visit_id)))
|
165
|
JOIN plot l ON ((place_visit.location_id = l.plot_id)))
|
166
|
JOIN taxonoccurrence o ON ((le.locationevent_id = o.locationevent_id)))
|
167
|
JOIN aggregateoccurrence ao ON ((o.taxonoccurrence_id = ao.taxonoccurrence_id)))
|
168
|
WHERE (s.shortname = :datasource::text)
|
169
|
ORDER BY p.projectname, l.authorlocationcode, ao.sourceaccessioncode;
|
170
|
/*
|
171
|
Note 1: `individuals` should be NULL for plots which use percent cover or line-intercept methods.
|
172
|
*/
|
173
|
|
174
|
-- _plots_11_count_of_stems_per_plot_in_each_project
|
175
|
SELECT p.projectname AS project_name,
|
176
|
l.authorlocationcode AS plot_code,
|
177
|
count(DISTINCT so.stemobservation_id) AS stems
|
178
|
FROM ((((((((project p
|
179
|
JOIN source s ON ((p.source_id = s.source_id)))
|
180
|
JOIN locationevent le ON ((p.project_id = le.project_id)))
|
181
|
JOIN locationevent sub_locationevent ON ((sub_locationevent.parent_id = le.locationevent_id)))
|
182
|
JOIN plot l ON ((le.location_id = l.plot_id)))
|
183
|
JOIN taxonoccurrence o ON ((sub_locationevent.locationevent_id = o.locationevent_id)))
|
184
|
JOIN aggregateoccurrence ao ON ((o.taxonoccurrence_id = ao.taxonoccurrence_id)))
|
185
|
JOIN plantobservation po ON ((po.aggregateoccurrence_id = ao.aggregateoccurrence_id)))
|
186
|
JOIN stemobservation so ON ((so.plantobservation_id = po.plantobservation_id)))
|
187
|
WHERE (s.shortname = :datasource::text)
|
188
|
GROUP BY p.projectname, l.authorlocationcode
|
189
|
ORDER BY p.projectname, l.authorlocationcode;
|
190
|
/*
|
191
|
Method: count records in stemobservation table
|
192
|
*/
|
193
|
|
194
|
-- _plots_12_count_of_verbatim_taxa_per_plot_in_each_project
|
195
|
SELECT p.projectname AS project_name,
|
196
|
l.authorlocationcode AS plot_code,
|
197
|
count(DISTINCT btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text)))) AS taxa
|
198
|
FROM (((((((project p
|
199
|
JOIN source s ON ((p.source_id = s.source_id)))
|
200
|
JOIN locationevent le ON ((p.project_id = le.project_id)))
|
201
|
JOIN locationevent sub_locationevent ON ((sub_locationevent.parent_id = le.locationevent_id)))
|
202
|
JOIN plot l ON ((le.location_id = l.plot_id)))
|
203
|
JOIN taxonoccurrence o ON ((sub_locationevent.locationevent_id = o.locationevent_id)))
|
204
|
JOIN taxondetermination td ON ((td.taxonoccurrence_id = o.taxonoccurrence_id)))
|
205
|
JOIN taxonverbatim tv ON ((td.taxonverbatim_id = tv.taxonverbatim_id)))
|
206
|
WHERE ((s.shortname = :datasource::text) AND (td.isoriginal = true))
|
207
|
GROUP BY p.projectname, l.authorlocationcode
|
208
|
ORDER BY p.projectname, l.authorlocationcode;
|
209
|
/*
|
210
|
Check: join to source db by all columns, returns same number of rows
|
211
|
Note: Must perform equivalent concatenation of taxonomic field in source db.
|
212
|
NOT YET READY, NEED TO INCLUDE SUBSPECIES, IF ANY
|
213
|
*/
|
214
|
|
215
|
-- _plots_13_list_of_distinct_verbatim_taxa_in_each_plot_in_each_p
|
216
|
SELECT DISTINCT p.projectname AS project_name,
|
217
|
l.authorlocationcode AS plot_code,
|
218
|
btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text))) AS taxon
|
219
|
FROM (((((((project p
|
220
|
JOIN source s ON ((p.source_id = s.source_id)))
|
221
|
JOIN locationevent le ON ((p.project_id = le.project_id)))
|
222
|
JOIN locationevent sub_locationevent ON ((sub_locationevent.parent_id = le.locationevent_id)))
|
223
|
JOIN plot l ON ((le.location_id = l.plot_id)))
|
224
|
JOIN taxonoccurrence o ON ((sub_locationevent.locationevent_id = o.locationevent_id)))
|
225
|
JOIN taxondetermination td ON ((td.taxonoccurrence_id = o.taxonoccurrence_id)))
|
226
|
JOIN taxonverbatim tv ON ((td.taxonverbatim_id = tv.taxonverbatim_id)))
|
227
|
WHERE ((s.shortname = :datasource::text) AND (td.isoriginal = true))
|
228
|
ORDER BY p.projectname, l.authorlocationcode, btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text)));
|
229
|
/*
|
230
|
Note: Must perform equivalent concatenation of taxonomic field in source db.
|
231
|
*/
|
232
|
|
233
|
-- _plots_14_count_of_indiv_per_verbatim_taxon_per_plot_in_each_pr
|
234
|
SELECT DISTINCT p.projectname AS project_name,
|
235
|
l.authorlocationcode AS plot_code,
|
236
|
btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text))) AS taxon,
|
237
|
sum(ao.count) AS individuals
|
238
|
FROM ((((((((project p
|
239
|
JOIN source s ON ((p.source_id = s.source_id)))
|
240
|
JOIN locationevent le ON ((p.project_id = le.project_id)))
|
241
|
JOIN locationevent sub_locationevent ON ((sub_locationevent.parent_id = le.locationevent_id)))
|
242
|
JOIN plot l ON ((le.location_id = l.plot_id)))
|
243
|
JOIN taxonoccurrence o ON ((sub_locationevent.locationevent_id = o.locationevent_id)))
|
244
|
JOIN taxondetermination td ON ((td.taxonoccurrence_id = o.taxonoccurrence_id)))
|
245
|
JOIN taxonverbatim tv ON ((td.taxonverbatim_id = tv.taxonverbatim_id)))
|
246
|
JOIN aggregateoccurrence ao ON ((o.taxonoccurrence_id = ao.taxonoccurrence_id)))
|
247
|
WHERE ((s.shortname = :datasource::text) AND (td.isoriginal = true))
|
248
|
GROUP BY p.projectname, l.authorlocationcode, btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text)))
|
249
|
ORDER BY p.projectname, l.authorlocationcode, btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text)));
|
250
|
/*
|
251
|
Note: Must do equivalent concatenation of taxonomic field in source db.
|
252
|
*/
|
253
|
|
254
|
-- _plots_15_pct_cover_of_each_verb_taxon_in_each_plot_in_each_pro
|
255
|
SELECT DISTINCT p.projectname AS project_name,
|
256
|
l.authorlocationcode AS plot_code,
|
257
|
btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text))) AS taxon,
|
258
|
sum(ci.coverpercent) AS totalpercentcover
|
259
|
FROM (((((((((project p
|
260
|
JOIN source s ON ((p.source_id = s.source_id)))
|
261
|
JOIN locationevent le ON ((p.project_id = le.project_id)))
|
262
|
JOIN locationevent sub_locationevent ON ((sub_locationevent.parent_id = le.locationevent_id)))
|
263
|
JOIN plot l ON ((le.location_id = l.plot_id)))
|
264
|
JOIN taxonoccurrence o ON ((sub_locationevent.locationevent_id = o.locationevent_id)))
|
265
|
JOIN taxondetermination td ON ((td.taxonoccurrence_id = o.taxonoccurrence_id)))
|
266
|
JOIN taxonverbatim tv ON ((td.taxonverbatim_id = tv.taxonverbatim_id)))
|
267
|
JOIN aggregateoccurrence ao ON ((o.taxonoccurrence_id = ao.taxonoccurrence_id)))
|
268
|
JOIN coverindex ci ON ((ao.coverindex_id = ci.coverindex_id)))
|
269
|
WHERE (((s.shortname = :datasource::text) AND (td.isoriginal = true)) AND (ci.coverpercent IS NOT NULL))
|
270
|
GROUP BY p.projectname, l.authorlocationcode, btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text)))
|
271
|
ORDER BY p.projectname, l.authorlocationcode, btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text)));
|
272
|
/*
|
273
|
Applies to: aggregate-cover plots only
|
274
|
Method: sums percent cover in aggregateoccurrence (as recorded in coverindex)
|
275
|
Check: join to source db by all columns, returns same number of rows
|
276
|
Note: Must do equivalent concatenation of taxonomic field in source db.
|
277
|
*/
|
278
|
|
279
|
-- _plots_16_intercepts_for_each_verb_taxon_in_each_plot_in_each_project
|
280
|
SELECT DISTINCT p.projectname AS project_name,
|
281
|
l.authorlocationcode AS plot_code,
|
282
|
btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text))) AS taxon,
|
283
|
sum(ao.linecover_m) AS intercept_cm
|
284
|
FROM ((((((((project p
|
285
|
JOIN source s ON ((p.source_id = s.source_id)))
|
286
|
JOIN locationevent le ON ((p.project_id = le.project_id)))
|
287
|
JOIN locationevent sub_locationevent ON ((sub_locationevent.parent_id = le.locationevent_id)))
|
288
|
JOIN plot l ON ((le.location_id = l.plot_id)))
|
289
|
JOIN taxonoccurrence o ON ((sub_locationevent.locationevent_id = o.locationevent_id)))
|
290
|
JOIN taxondetermination td ON ((td.taxonoccurrence_id = o.taxonoccurrence_id)))
|
291
|
JOIN taxonverbatim tv ON ((td.taxonverbatim_id = tv.taxonverbatim_id)))
|
292
|
JOIN aggregateoccurrence ao ON ((o.taxonoccurrence_id = ao.taxonoccurrence_id)))
|
293
|
WHERE (((s.shortname = :datasource::text) AND (td.isoriginal = true)) AND (ao.linecover_m IS NOT NULL))
|
294
|
GROUP BY p.projectname, l.authorlocationcode, btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text)))
|
295
|
ORDER BY p.projectname, l.authorlocationcode, btrim((((((((''::text || COALESCE(tv.family, ''::text)) || ' '::text) || COALESCE(tv.genus, ''::text)) || ' '::text) || COALESCE(tv.specific_epithet, ''::text)) || ' '::text) || COALESCE(tv.morphospecies, ''::text)));
|
296
|
/*
|
297
|
Note 1: Assumes identical concatenation of taxonomic fields to form verbatim taxon name in origina db
|
298
|
Note 2: Grouping mean cover for entire plot combines plots with subplots (separate cover measure for each species in each subplot) with plots with strata (separate cover measures for each species in each stratum) with plots without subplots or strata (one cover measure per species per plot.
|
299
|
*/
|
300
|
|
301
|
-- _plots_17_count_of_subplots_per_plot_for_each_project
|
302
|
SELECT p.projectname AS project_name,
|
303
|
l.authorlocationcode AS plot_code,
|
304
|
count(DISTINCT sub_locationevent.locationevent_id) AS subplots
|
305
|
FROM ((((project p
|
306
|
JOIN source s ON ((p.source_id = s.source_id)))
|
307
|
JOIN locationevent le ON ((p.project_id = le.project_id)))
|
308
|
JOIN locationevent sub_locationevent ON ((sub_locationevent.parent_id = le.locationevent_id)))
|
309
|
JOIN plot l ON ((le.location_id = l.plot_id)))
|
310
|
WHERE (s.shortname = :datasource::text)
|
311
|
GROUP BY p.projectname, l.authorlocationcode
|
312
|
ORDER BY p.projectname, l.authorlocationcode;
|
313
|
|
314
|
-- _plots_18_list_of_subplots_codes_for_each_plot_for_each_project
|
315
|
SELECT p.projectname AS project_name,
|
316
|
l.authorlocationcode AS plot_code,
|
317
|
sub_locationevent.authoreventcode AS subplot_code
|
318
|
FROM ((((project p
|
319
|
JOIN source s ON ((p.source_id = s.source_id)))
|
320
|
JOIN locationevent le ON ((p.project_id = le.project_id)))
|
321
|
JOIN locationevent sub_locationevent ON ((sub_locationevent.parent_id = le.locationevent_id)))
|
322
|
JOIN plot l ON ((sub_locationevent.location_id = l.plot_id)))
|
323
|
WHERE (s.shortname = :datasource::text)
|
324
|
ORDER BY p.projectname, l.authorlocationcode;
|
325
|
/*
|
326
|
DOESN''T YET WORK PROPERLY
|
327
|
*/
|
328
|
|
329
|
-- _plots_19_count_of_censuses_per_plot_in_each_project
|
330
|
SELECT project.projectname AS project_name,
|
331
|
plot.authorlocationcode AS plot_code,
|
332
|
count(*) AS inventories
|
333
|
FROM ((plot plot(location_id)
|
334
|
JOIN locationevent USING (location_id))
|
335
|
LEFT JOIN project USING (project_id))
|
336
|
WHERE (plot.source_id = ( SELECT source_by_shortname(:datasource::text) AS source_by_shortname))
|
337
|
GROUP BY project.projectname, plot.authorlocationcode
|
338
|
ORDER BY project.projectname, plot.authorlocationcode;
|
339
|
|
340
|
-- _plots_20_tnrs_input_names
|
341
|
SELECT DISTINCT taxonlabel.taxonomicname AS tnrs_input_name
|
342
|
FROM taxonlabel
|
343
|
WHERE ((taxonlabel.source_id = ( SELECT source_by_shortname(:datasource::text) AS source_by_shortname)) AND (taxonlabel.taxonomicname IS NOT NULL));
|
344
|
|
345
|
-- _plots_21_tnrs_output_names
|
346
|
SET enable_hashjoin = off;
|
347
|
SELECT DISTINCT taxon_scrub.scrubbed_unique_taxon_name AS tnrs_output_name
|
348
|
FROM (taxonlabel
|
349
|
JOIN "TNRS".taxon_scrub ON ((taxon_scrub."concatenatedScientificName" = taxonlabel.taxonomicname)))
|
350
|
WHERE ((taxonlabel.source_id = ( SELECT source_by_shortname(:datasource::text) AS source_by_shortname)) AND (taxon_scrub."concatenatedScientificName" IS NOT NULL));
|
351
|
SET enable_hashjoin = DEFAULT;
|