SALVIAS aggregating validations¶
result sets¶
current queries¶
past queries¶
2012-11-28¶
boyle_plot_validations.txt (e-mail from Brad Boyle on 2012-11-28)
###############################################
-- Brad Boyle / SALVIAS plots validations
###############################################
-- extract of boyle-salvias plots for validation
-- these queries pull the original data from SALVIAS plots
-- project_id=2 is "SALVIAS:Boyle Transects"
USE salvias_plots;
-- Count of species per plot from three plots
SELECT PlotCode, COUNT(DISTINCT Family, Genus, Species) as totSpecies
FROM PlotMetadata p JOIN PlotObservations o
ON p.PlotID=o.PlotID
WHERE project_id=2
GROUP BY PlotCode
ORDER BY PlotCode;
-- List of species per plot, three plots
SELECT DISTINCT PlotCode, CONCAT(IF(Genus IS NULL OR Genus='',IFNULL(Family,''),''),' ',IFNULL(Genus,''),' ', IFNULL(Species,'')) AS morphospecies
FROM PlotObservations
WHERE PlotCode IN ('m2250-1','c2250-1','e2250-1')
ORDER BY PlotCode, morphospecies;
-- Count of individuals per species, same plots
SELECT
PlotCode,
CONCAT(IF(Genus IS NULL OR Genus='',IFNULL(Family,''),''),' ',IFNULL(Genus,''),' ', IFNULL(Species,'')) AS morphospecies,
SUM(NoInd) AS individuals
FROM PlotObservations
WHERE PlotCode IN ('m2250-1','c2250-1','e2250-1')
GROUP BY PlotCode, morphospecies
ORDER BY PlotCode, morphospecies;
-- Count of stems >=2.5 cm dbh per individual, same plots
SELECT
PlotCode,
Ind as individualID,
CONCAT(IF(Genus IS NULL OR Genus='',IFNULL(Family,''),''),' ',IFNULL(Genus,''),' ', IFNULL(Species,'')) AS morphospecies,
COUNT(DISTINCT stem_id) AS stems
FROM PlotObservations o JOIN stems s
ON o.PlotObsID=s.PlotObsID
WHERE PlotCode IN ('m2250-1','c2250-1','e2250-1')
GROUP BY PlotCode, morphospecies, individualID
ORDER BY PlotCode, morphospecies, individualID;
-- Count of individuals with >= one stem >= 2.5 cm dbh per plot
SELECT
PlotCode, SUM(DISTINCT Ind) AS individuals
FROM PlotMetadata p JOIN PlotObservations o JOIN stems s
ON p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
WHERE project_id=2
AND stem_dbh>=2.5
GROUP BY PlotCode
ORDER BY PlotCode;
-- Count of stems >= 2.5 cm dbh per plot
SELECT
PlotCode, COUNT(DISTINCT stem_id) AS stems
FROM PlotMetadata p JOIN PlotObservations o JOIN stems s
ON p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
WHERE project_id=2
AND stem_dbh>=2.5
GROUP BY PlotCode
ORDER BY PlotCode;
-- Count of stems >=10 cm dbh per plot
SELECT
PlotCode, COUNT(DISTINCT stem_id) AS stems
FROM PlotMetadata p JOIN PlotObservations o JOIN stems s
ON p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
WHERE project_id=2
AND stem_dbh>=10
GROUP BY PlotCode
ORDER BY PlotCode;
2011-12-8¶
SALVIAS_queries_and_examples.txt (e-mail from Brad Boyle on 2011-12-8)
nimoy > MySQL db salvias_plots
SELECT COUNT(*) FROM projects;
SELECT COUNT(*) FROM plotMetadata;
SELECT pr.project_id, project_name, COUNT(PlotID)
FROM projects pr JOIN plotMetadata p
ON pr.project_id=p.project_id
GROUP BY pr.project_id, project_name;
SELECT DISTINCT pr.project_id, project_name, PlotMethod, m.MethodCode, m.Description
FROM projects pr JOIN plotMetadata p JOIN lookup_MethodCode m
ON pr.project_id=p.project_id AND p.MethodCode=m.MethodCode
LIMIT 10;
SELECT p.PlotID, p.SiteCode, COUNT(*)
FROM projects pr JOIN plotMetadata p JOIN plotObservations o
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID
WHERE p.project_id=2
GROUP BY p.PlotID, p.SiteCode;
SELECT NoInd, COUNT(*) AS observations
FROM plotObservations o JOIN plotMetadata p
ON o.PlotID=p.PlotID
WHERE project_id=2
GROUP BY NoInd;
SELECT p.PlotID, p.SiteCode, SUM(NoInd) AS Individuals
FROM projects pr JOIN plotMetadata p JOIN plotObservations o
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID
WHERE p.project_id=2
GROUP BY p.PlotID, p.SiteCode;
SELECT DISTINCT pr.project_id, project_name, PlotMethod, m.MethodCode, m.Description
FROM projects pr JOIN plotMetadata p JOIN lookup_MethodCode m
ON pr.project_id=p.project_id AND p.MethodCode=m.MethodCode
WHERE m.MethodCode=8;
SELECT NoInd, COUNT(*) AS observations
FROM plotObservations o JOIN plotMetadata p JOIN lookup_MethodCode m
ON o.PlotID=p.PlotID AND p.MethodCode=m.MethodCode
WHERE project_id=2
GROUP BY NoInd;
SELECT p.PlotID, p.SiteCode, SUM(NoInd) AS Individuals
FROM projects pr JOIN plotMetadata p JOIN plotObservations o
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID
WHERE p.project_id=1
GROUP BY p.PlotID, p.SiteCode
LIMIT 10;
SELECT PlotMethod, MethodCode, Description, COUNT(project_id) as projects
FROM (
SELECT DISTINCT p.PlotMethod, p.MethodCode, p.Description, p.project_id
FROM (
SELECT project_id, PlotID, PlotMethod, m.MethodCode, m.Description
FROM plotMetadata p JOIN lookup_MethodCode m
ON p.MethodCode=m.MethodCode
) p JOIN plotObservations o JOIN stems s
ON p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
GROUP BY project_id
) AS a
GROUP BY PlotMethod, MethodCode, Description;
SELECT DISTINCT pr.project_id, project_name
FROM projects pr JOIN plotMetadata p JOIN plotObservations o JOIN stems s
ON pr.project_id=p.project_id AND p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
WHERE p.MethodCode=3;
SELECT p.PlotID, SiteName as plot, COUNT(*) AS stems
FROM plotMetadata p JOIN plotObservations o JOIN stems s
ON p.PlotID=o.PlotID AND o.PlotObsID=s.PlotObsID
WHERE p.project_id=2
GROUP BY p.PlotID, SiteName
LIMIT 10;
SELECT p.PlotID, SiteName AS plot, COUNT(DISTINCT Family, Genus, Species) AS SpeciesCount
FROM plotMetadata p JOIN plotObservations o
ON p.PlotID=o.PlotID
WHERE project_id=2
GROUP BY p.PlotID, SiteName;
SELECT DISTINCT p.PlotID, SiteName AS plot, Family, CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName
FROM plotMetadata p JOIN plotObservations o
ON p.PlotID=o.PlotID
WHERE p.PlotID=298;
SELECT name_status, count(*) FROM plotObservations GROUP BY name_status;
SELECT DISTINCT p.PlotID, SiteName AS plot, Family,
CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName, name_status
FROM plotMetadata p JOIN plotObservations o
ON p.PlotID=o.PlotID
WHERE p.PlotID=298;
SELECT DISTINCT p.PlotID, SiteName AS plot, Family,
CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName, name_status
FROM plotMetadata p JOIN plotObservations o
ON p.PlotID=o.PlotID
WHERE p.PlotID=298 AND name_status=1;
SELECT p.PlotID, SiteCode AS plot, o.Line as subplot, COUNT(*) AS individuals
FROM plotMetadata p JOIN plotObservations o
ON p.PlotID=o.PlotID
WHERE p.PlotID=298
GROUP BY p.PlotID, plot, subplot;
SELECT p.PlotID, SiteCode AS plot, o.Line as subplot, SUM(NoInd) AS individuals
FROM plotMetadata p JOIN plotObservations o
ON p.PlotID=o.PlotID
WHERE p.PlotID=298
GROUP BY p.PlotID, plot, subplot;
SELECT p.PlotID, SiteCode AS plot, o.Line as subplot, SUM(NoInd) AS individuals
FROM plotMetadata p JOIN plotObservations o
ON p.PlotID=o.PlotID
WHERE p.PlotID=1
GROUP BY p.PlotID, plot, subplot;
SELECT COUNT(*) FROM plotMetadata WHERE MethodCode=1;
SELECT PlotID FROM plotMetadata WHERE MethodCode=1 LIMIT 1;
SELECT p.PlotID, SiteCode AS plot, Family,
CONCAT_WS(' ',IFNULL(Genus,''), IFNULL(Species,'')) AS SpeciesName, cover_percent
FROM plotMetadata p JOIN plotObservations o
ON p.PlotID=o.PlotID
WHERE p.PlotID=24589;
SELECT p.PlotID, p.SiteCode as plot, Country, PolDiv1 AS stateProvince, pol2 AS countyParish,
LatDec as latitude, LongDec as longitude, Elev as elevation
FROM projects pr JOIN plotMetadata p
ON pr.project_id=p.project_id
WHERE pr.project_id=1
LIMIT 20;
SELECT AccessCode, COUNT(*)
FROM plotMetadata
GROUP BY AccessCode;
SELECT pr.project_id, project_name, project_pi, allow_download_all, PlotID, SiteCode, Country
FROM projects pr JOIN plotMetadata p
ON pr.project_id=p.project_id
WHERE p.AccessCode=1;
Query extraction from document¶
- Replace regexp
^SELECT[^~]*?;
with BeanShell expression_0.replaceAll("(?m)^","~")
- Replace regexp
^(?![~\n]).*\n
with text""
- Replace regexp
^~
with text""
- Replace regexp
\n{2,}
with text\n\n