1 |
|
-- -------------------------------------------------------------------------------
|
2 |
|
-- Quantitative validation queries against the trait table in db bien2 on nimoy
|
3 |
|
-- -------------------------------------------------------------------------------
|
4 |
|
|
5 |
|
USE bien2;
|
6 |
|
|
7 |
|
-- ------------------
|
8 |
|
-- 1. Count records
|
9 |
|
-- ------------------
|
10 |
|
SELECT COUNT(*) AS totalrecords
|
11 |
|
FROM TraitObservation;
|
12 |
|
|
13 |
|
-- ------------------
|
14 |
|
-- 2. Count trait names
|
15 |
|
-- ------------------
|
16 |
|
SELECT COUNT(DISTINCT TraitName) AS traits
|
17 |
|
FROM TraitObservation;
|
18 |
|
|
19 |
|
-- ------------------
|
20 |
|
-- 3. List trait names
|
21 |
|
-- ------------------
|
22 |
|
SELECT DISTINCT TraitName AS trait
|
23 |
|
FROM TraitObservation
|
24 |
|
ORDER BY TraitName;
|
25 |
|
|
26 |
|
-- ------------------
|
27 |
|
-- 4. Count records per trait
|
28 |
|
-- ------------------
|
29 |
|
SELECT TraitName AS trait, COUNT(*) AS measurements
|
30 |
|
FROM TraitObservation
|
31 |
|
GROUP BY TraitName
|
32 |
|
ORDER BY TraitName;
|
33 |
|
|
34 |
|
-- ------------------
|
35 |
|
-- 5. Count taxa
|
36 |
|
--
|
37 |
|
-- Note: No morphospecies in trait table, therefore count
|
38 |
|
-- taxon + authority only
|
39 |
|
-- ------------------
|
40 |
|
SELECT COUNT(DISTINCT TRIM(CONCAT(taxonCorrected,' ',IFNULL(authorityCorrected,'')))) AS taxa
|
41 |
|
FROM TraitObservation
|
42 |
|
WHERE taxonCorrected IS NOT NULL;
|
43 |
|
|
44 |
|
-- ------------------
|
45 |
|
-- 6. List taxa
|
46 |
|
--
|
47 |
|
-- Note 1: No morphospecies in trait table, use taxon + authority
|
48 |
|
-- Note 2: Note formation of taxonCorrected: includes family ONLY if
|
49 |
|
-- taxon is not determined at least to genus
|
50 |
|
-- ------------------
|
51 |
|
SELECT DISTINCT TRIM(CONCAT(IFNULL(taxonCorrected,''),' ',IFNULL(authorityCorrected,''))) AS taxonwithauthor
|
52 |
|
FROM TraitObservation
|
53 |
|
ORDER BY taxonWithAuthor;
|
54 |
|
|
55 |
|
-- ------------------
|
56 |
|
-- 7. Trait, value and units for first 5000 records
|
57 |
|
-- ------------------
|
58 |
|
SELECT TraitName AS trait, TraitValue AS value, Unit AS units
|
59 |
|
FROM TraitObservation
|
60 |
|
ORDER BY TraitName, TraitValue, Unit
|
61 |
|
LIMIT 5000;
|
62 |
|
|
63 |
|
-- ------------------
|
64 |
|
-- 8. Taxon, trait and value for first 5000 records
|
65 |
|
-- ------------------
|
66 |
|
SELECT TRIM(CONCAT(IFNULL(taxonCorrected,''),' ',IFNULL(authorityCorrected,''))) AS taxonwithauthor,
|
67 |
|
TraitName AS trait, TraitValue AS value
|
68 |
|
FROM TraitObservation
|
69 |
|
ORDER BY taxonWithAuthor, TraitName, TraitValue
|
70 |
|
LIMIT 5000;
|
validation/**: removed old versions of by=-tagged files. these were not renamed in the last commit because there were newer versions that they collided with. note that because , sorts before . , the newer version (with more ",name@inst" tags) was correctly renamed instead of the older version.