Project

General

Profile

1
SELECT '# projects' AS ___;
2
SELECT count(*) AS count FROM projects;
3

    
4
SELECT 'projects' AS ___;
5
SELECT CAST(project_id AS char) AS project FROM projects ORDER BY project;
6

    
7
SELECT 'each project\'s # locations' AS ___;
8
SELECT
9
    CAST(projects.project_id AS char) AS project
10
    , count(PlotID) AS locations_count
11
FROM projects
12
JOIN plotMetadata ON plotMetadata.project_id = projects.project_id
13
GROUP BY project
14
ORDER BY project
15
;
16

    
17
SELECT '# locations' AS ___;
18
SELECT count(*) AS count
19
FROM
20
(
21
    SELECT DISTINCT LatDec, LongDec FROM plotMetadata
22
) locationcoords
23
;
24

    
25
SELECT '# location events' AS ___;
26
SELECT count(*) AS count FROM plotMetadata;
27

    
28
SELECT '1st methods' AS ___;
29
SELECT DISTINCT
30
    CAST(projects.project_id AS char) AS project
31
    , PlotMethod AS method
32
FROM projects
33
JOIN plotMetadata ON plotMetadata.project_id = projects.project_id
34
ORDER BY project, method
35
LIMIT 10;
36

    
37
SELECT '1st observation measures' AS ___;
38
SELECT DISTINCT
39
    CAST(projects.project_id AS char) AS project
40
    , lookup_MethodCode.Description AS observationmeasure
41
FROM projects
42
JOIN plotMetadata ON plotMetadata.project_id = projects.project_id
43
JOIN lookup_MethodCode ON lookup_MethodCode.MethodCode = plotMetadata.MethodCode
44
ORDER BY project, observationmeasure
45
LIMIT 10;
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
*/
(2-2/3)