1
|
-- -------------------------------------------------------------------------------
|
2
|
-- Quantitative validation queries against the trait table in db bien2 on nimoy
|
3
|
--
|
4
|
-- For all queries, omit records where taxon or traitName are null or blank
|
5
|
-- This filtering would have been performed prior to import
|
6
|
-- -------------------------------------------------------------------------------
|
7
|
|
8
|
USE bien2_staging;
|
9
|
|
10
|
-- ------------------
|
11
|
-- 1. Count records
|
12
|
-- ------------------
|
13
|
SELECT COUNT(*) AS totalrecords
|
14
|
FROM TraitObservation
|
15
|
WHERE Taxon IS NOT NULL AND Taxon<>'' AND TraitName IS NOT NULL AND TraitName<>''
|
16
|
;
|
17
|
|
18
|
-- ------------------
|
19
|
-- 2. Count trait names
|
20
|
-- ------------------
|
21
|
SELECT COUNT(DISTINCT TraitName) AS traits
|
22
|
FROM TraitObservation
|
23
|
WHERE Taxon IS NOT NULL AND Taxon<>'' AND TraitName IS NOT NULL AND TraitName<>''
|
24
|
;
|
25
|
|
26
|
-- ------------------
|
27
|
-- 3. List trait names
|
28
|
-- ------------------
|
29
|
SELECT DISTINCT TraitName AS trait
|
30
|
FROM TraitObservation
|
31
|
WHERE Taxon IS NOT NULL AND Taxon<>'' AND TraitName IS NOT NULL AND TraitName<>''
|
32
|
ORDER BY trait
|
33
|
;
|
34
|
|
35
|
-- ------------------
|
36
|
-- 4. Count records per trait
|
37
|
-- ------------------
|
38
|
SELECT TraitName AS trait, COUNT(*) AS measurements
|
39
|
FROM TraitObservation
|
40
|
WHERE Taxon IS NOT NULL AND Taxon<>'' AND TraitName IS NOT NULL AND TraitName<>''
|
41
|
GROUP BY trait
|
42
|
ORDER BY trait
|
43
|
;
|
44
|
|
45
|
-- ------------------
|
46
|
-- 5. Count taxa
|
47
|
-- ------------------
|
48
|
SELECT COUNT(DISTINCT
|
49
|
TRIM(CONCAT_WS(' ',IFNULL(Taxon,''),IFNULL(AuthorOfScientificName,'')))
|
50
|
) AS taxa
|
51
|
FROM TraitObservation
|
52
|
WHERE Taxon IS NOT NULL AND Taxon<>'' AND TraitName IS NOT NULL AND TraitName<>''
|
53
|
;
|
54
|
|
55
|
-- ------------------
|
56
|
-- 6. List distinct taxa
|
57
|
-- ------------------
|
58
|
SELECT DISTINCT
|
59
|
TRIM(CONCAT_WS(' ',IFNULL(Taxon,''),IFNULL(AuthorOfScientificName,'')))
|
60
|
AS taxonwithauthor
|
61
|
FROM TraitObservation
|
62
|
WHERE Taxon IS NOT NULL AND Taxon<>'' AND TraitName IS NOT NULL AND TraitName<>''
|
63
|
ORDER BY taxonwithauthor
|
64
|
;
|
65
|
|
66
|
-- ------------------
|
67
|
-- 7. Trait, value and units
|
68
|
-- ------------------
|
69
|
SELECT TraitName AS trait, TraitValue AS value, Unit AS units
|
70
|
FROM TraitObservation
|
71
|
WHERE Taxon IS NOT NULL AND Taxon<>'' AND TraitName IS NOT NULL AND TraitName<>''
|
72
|
ORDER BY trait, `value`, units
|
73
|
;
|
74
|
|
75
|
-- ------------------
|
76
|
-- 8. Taxon, trait and value for first 5000 records
|
77
|
-- ------------------
|
78
|
SELECT
|
79
|
TRIM(CONCAT_WS(' ',IFNULL(Taxon,''),IFNULL(AuthorOfScientificName,'')))
|
80
|
AS taxonwithauthor,
|
81
|
TraitName AS trait, TraitValue AS `value`
|
82
|
FROM TraitObservation
|
83
|
WHERE Taxon IS NOT NULL AND Taxon<>'' AND TraitName IS NOT NULL AND TraitName<>''
|
84
|
ORDER BY taxonwithauthor, trait, `value`
|
85
|
;
|