1
|
SELECT '# projects' AS ___;
|
2
|
SELECT count(*) AS count FROM projects;
|
3
|
|
4
|
SELECT 'projects' AS ___;
|
5
|
SELECT CAST(project_name AS text) AS projectname
|
6
|
FROM projects
|
7
|
ORDER BY projectname
|
8
|
;
|
9
|
|
10
|
SELECT 'each project''s # locations' AS ___;
|
11
|
SELECT
|
12
|
CAST(project_name AS text) AS projectname
|
13
|
, count("PlotID") AS locations_count
|
14
|
FROM projects
|
15
|
JOIN "plotMetadata" ON "plotMetadata".project_id = projects.project_id
|
16
|
GROUP BY projectname
|
17
|
ORDER BY projectname
|
18
|
;
|
19
|
|
20
|
SELECT '# top-level locations' AS ___;
|
21
|
SELECT count(*) AS count FROM "plotMetadata";
|
22
|
|
23
|
SELECT '# top-level location events' AS ___;
|
24
|
SELECT count(*) AS count FROM "plotMetadata";
|
25
|
|
26
|
SELECT '1st methods' AS ___;
|
27
|
SELECT DISTINCT
|
28
|
CAST(project_name AS text) AS projectname
|
29
|
, "PlotMethod" AS method
|
30
|
FROM projects
|
31
|
JOIN "plotMetadata" ON "plotMetadata".project_id = projects.project_id
|
32
|
ORDER BY projectname, method
|
33
|
LIMIT 10
|
34
|
;
|
35
|
|
36
|
SELECT '1st observation measures' AS ___;
|
37
|
SELECT DISTINCT
|
38
|
CAST(project_name AS text) AS projectname
|
39
|
, "lookup_MethodCode"."Description" AS observationmeasure
|
40
|
FROM projects
|
41
|
JOIN "plotMetadata" ON "plotMetadata".project_id = projects.project_id
|
42
|
JOIN "lookup_MethodCode" ON "lookup_MethodCode"."MethodCode" = "plotMetadata"."MethodCode"
|
43
|
ORDER BY projectname, observationmeasure
|
44
|
LIMIT 10
|
45
|
;
|
46
|
|
47
|
/*
|
48
|
SELECT p.PlotID, p.SiteCode, COUNT(*)
|
49
|
FROM projects pr JOIN "plotMetadata" p JOIN plotObservations o
|
50
|
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID
|
51
|
WHERE p.project_id=2
|
52
|
GROUP BY p.PlotID, p.SiteCode;
|
53
|
|
54
|
SELECT NoInd, COUNT(*) AS observations
|
55
|
FROM plotObservations o JOIN "plotMetadata" p
|
56
|
ON o.PlotID=p.PlotID
|
57
|
WHERE project_id=2
|
58
|
GROUP BY NoInd;
|
59
|
|
60
|
SELECT p.PlotID, p.SiteCode, SUM(NoInd) AS Individuals
|
61
|
FROM projects pr JOIN "plotMetadata" p JOIN plotObservations o
|
62
|
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID
|
63
|
WHERE p.project_id=2
|
64
|
GROUP BY p.PlotID, p.SiteCode;
|
65
|
|
66
|
SELECT DISTINCT "pr".project_id, project_name, "PlotMethod", m."MethodCode", m."Description"
|
67
|
FROM projects pr JOIN "plotMetadata" p JOIN "lookup_MethodCode" m
|
68
|
ON pr.project_id=p.project_id AND p."MethodCode"=m."MethodCode"
|
69
|
WHERE m."MethodCode"=8;
|
70
|
|
71
|
SELECT NoInd, COUNT(*) AS observations
|
72
|
FROM plotObservations o JOIN "plotMetadata" p JOIN "lookup_MethodCode" m
|
73
|
ON o.PlotID=p.PlotID AND p."MethodCode"=m."MethodCode"
|
74
|
WHERE project_id=2
|
75
|
GROUP BY NoInd;
|
76
|
|
77
|
SELECT p.PlotID, p.SiteCode, SUM(NoInd) AS Individuals
|
78
|
FROM projects pr JOIN "plotMetadata" p JOIN plotObservations o
|
79
|
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID
|
80
|
WHERE p.project_id=1
|
81
|
GROUP BY p.PlotID, p.SiteCode
|
82
|
LIMIT 10;
|
83
|
|
84
|
SELECT "PlotMethod", "MethodCode", "Description", COUNT(project_id) as projects
|
85
|
FROM (
|
86
|
SELECT DISTINCT "p"."PlotMethod", p."MethodCode", p."Description", p.project_id
|
87
|
FROM (
|
88
|
SELECT project_id, PlotID, "PlotMethod", m."MethodCode", m."Description"
|
89
|
FROM "plotMetadata" p JOIN "lookup_MethodCode" m
|
90
|
ON p."MethodCode"=m."MethodCode"
|
91
|
) p JOIN plotObservations o JOIN stems s
|
92
|
ON p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
|
93
|
GROUP BY project_id
|
94
|
) AS a
|
95
|
GROUP BY "PlotMethod", "MethodCode", "Description";
|
96
|
|
97
|
SELECT DISTINCT "pr".project_id, project_name
|
98
|
FROM projects pr JOIN "plotMetadata" p JOIN plotObservations o JOIN stems s
|
99
|
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
|
100
|
WHERE p."MethodCode"=3;
|
101
|
|
102
|
SELECT p.PlotID, SiteName as plot, COUNT(*) AS stems
|
103
|
FROM "plotMetadata" p JOIN plotObservations o JOIN stems s
|
104
|
ON p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
|
105
|
WHERE p.project_id=2
|
106
|
GROUP BY p.PlotID, SiteName
|
107
|
LIMIT 10;
|
108
|
|
109
|
SELECT p.PlotID, SiteName AS plot, COUNT(DISTINCT "Family", Genus, Species) AS SpeciesCount
|
110
|
FROM "plotMetadata" p JOIN plotObservations o
|
111
|
ON p.PlotID=o.PlotID
|
112
|
WHERE project_id=2
|
113
|
GROUP BY p.PlotID, SiteName;
|
114
|
|
115
|
SELECT DISTINCT "p".PlotID, SiteName AS plot, Family, CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName
|
116
|
FROM "plotMetadata" p JOIN plotObservations o
|
117
|
ON p.PlotID=o.PlotID
|
118
|
WHERE p.PlotID=298;
|
119
|
|
120
|
SELECT name_status, count(*) FROM plotObservations GROUP BY name_status;
|
121
|
|
122
|
SELECT DISTINCT "p".PlotID, SiteName AS plot, Family,
|
123
|
CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName, name_status
|
124
|
FROM "plotMetadata" p JOIN plotObservations o
|
125
|
ON p.PlotID=o.PlotID
|
126
|
WHERE p.PlotID=298;
|
127
|
|
128
|
SELECT DISTINCT "p".PlotID, SiteName AS plot, Family,
|
129
|
CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName, name_status
|
130
|
FROM "plotMetadata" p JOIN plotObservations o
|
131
|
ON p.PlotID=o.PlotID
|
132
|
WHERE p.PlotID=298 AND name_status=1;
|
133
|
|
134
|
SELECT p.PlotID, SiteCode AS plot, o.Line as subplot, COUNT(*) AS individuals
|
135
|
FROM "plotMetadata" p JOIN plotObservations o
|
136
|
ON p.PlotID=o.PlotID
|
137
|
WHERE p.PlotID=298
|
138
|
GROUP BY p.PlotID, plot, subplot;
|
139
|
|
140
|
SELECT p.PlotID, SiteCode AS plot, o.Line as subplot, SUM(NoInd) AS individuals
|
141
|
FROM "plotMetadata" p JOIN plotObservations o
|
142
|
ON p.PlotID=o.PlotID
|
143
|
WHERE p.PlotID=298
|
144
|
GROUP BY p.PlotID, plot, subplot;
|
145
|
|
146
|
SELECT p.PlotID, SiteCode AS plot, o.Line as subplot, SUM(NoInd) AS individuals
|
147
|
FROM "plotMetadata" p JOIN plotObservations o
|
148
|
ON p.PlotID=o.PlotID
|
149
|
WHERE p.PlotID=1
|
150
|
GROUP BY p.PlotID, plot, subplot;
|
151
|
|
152
|
SELECT COUNT(*) FROM "plotMetadata" WHERE "MethodCode"=1;
|
153
|
|
154
|
SELECT PlotID FROM "plotMetadata" WHERE "MethodCode"=1 LIMIT 1;
|
155
|
|
156
|
SELECT p.PlotID, SiteCode AS plot, Family,
|
157
|
CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName, cover_percent
|
158
|
FROM "plotMetadata" p JOIN plotObservations o
|
159
|
ON p.PlotID=o.PlotID
|
160
|
WHERE p.PlotID=24589;
|
161
|
|
162
|
SELECT p.PlotID, p.SiteCode as plot, Country, PolDiv1 AS stateProvince, pol2 AS countyParish,
|
163
|
LatDec as latitude, LongDec as longitude, Elev as elevation
|
164
|
FROM projects pr JOIN "plotMetadata" p
|
165
|
ON pr.project_id=p.project_id
|
166
|
WHERE pr.project_id=1
|
167
|
LIMIT 20;
|
168
|
|
169
|
SELECT AccessCode, COUNT(*)
|
170
|
FROM "plotMetadata"
|
171
|
GROUP BY AccessCode;
|
172
|
|
173
|
SELECT pr.project_id, project_name, project_pi, allow_download_all, PlotID, SiteCode, Country
|
174
|
FROM projects pr JOIN "plotMetadata" p
|
175
|
ON pr.project_id=p.project_id
|
176
|
WHERE p.AccessCode=1;
|
177
|
*/
|