Project

General

Profile

1
SELECT '# specimen replicates' AS ___;
2
SELECT count(*) AS count
3
FROM specimenreplicate
4
WHERE datasource_id =
5
    (SELECT party_id FROM party WHERE organizationname = :datasource)
6
;
7

    
8
SELECT '# families' AS ___;
9
SELECT count(DISTINCT plantname.plantname_id) AS count
10
FROM specimenreplicate
11
JOIN taxondetermination USING (taxonoccurrence_id)
12
JOIN plantconcept USING (plantconcept_id)
13
JOIN plantname_ancestor USING (plantname_id)
14
JOIN plantname
15
    ON plantname.plantname_id = plantname_ancestor.ancestor_id
16
    AND plantname.rank = 'family'
17
WHERE datasource_id =
18
    (SELECT party_id FROM party WHERE organizationname = :datasource)
19
AND taxondetermination.isoriginal
20
;
21

    
22
SELECT '# genera' AS ___;
23
SELECT count(DISTINCT plantname.plantname_id) AS count
24
FROM specimenreplicate
25
JOIN taxondetermination USING (taxonoccurrence_id)
26
JOIN plantconcept USING (plantconcept_id)
27
JOIN plantname_ancestor USING (plantname_id)
28
JOIN plantname
29
    ON plantname.plantname_id = plantname_ancestor.ancestor_id
30
    AND plantname.rank = 'genus'
31
WHERE datasource_id =
32
    (SELECT party_id FROM party WHERE organizationname = :datasource)
33
AND taxondetermination.isoriginal
34
;
35

    
36
SELECT '# species' AS ___;
37
SELECT
38
    count(DISTINCT genus_plantname.plantname_id
39
        ||','||species_plantname.plantname_id) AS count
40
FROM specimenreplicate
41
JOIN taxondetermination USING (taxonoccurrence_id)
42
JOIN plantconcept USING (plantconcept_id)
43
JOIN plantname_ancestor USING (plantname_id)
44
JOIN plantname AS genus_plantname
45
    ON genus_plantname.plantname_id = plantname_ancestor.ancestor_id
46
    AND genus_plantname.rank = 'genus'
47
JOIN plantname AS species_plantname
48
    ON species_plantname.plantname_id = plantname_ancestor.ancestor_id
49
    AND species_plantname.rank = 'species'
50
WHERE datasource_id =
51
    (SELECT party_id FROM party WHERE organizationname = :datasource)
52
;
53

    
54
SELECT '# binomials' AS ___;
55
SELECT count(DISTINCT plantname.plantname_id) AS count
56
FROM specimenreplicate
57
JOIN taxondetermination USING (taxonoccurrence_id)
58
JOIN plantconcept USING (plantconcept_id)
59
JOIN plantname_ancestor USING (plantname_id)
60
JOIN plantname
61
    ON plantname.plantname_id = plantname_ancestor.ancestor_id
62
    AND plantname.rank = 'binomial'
63
WHERE datasource_id =
64
    (SELECT party_id FROM party WHERE organizationname = :datasource)
65
AND taxondetermination.isoriginal
66
;
67

    
68
SELECT 'collection codes' AS ___;
69
SELECT DISTINCT collectioncode_dwc
70
FROM specimenreplicate
71
WHERE datasource_id =
72
    (SELECT party_id FROM party WHERE organizationname = :datasource)
73
;
74

    
75
SELECT '# catalog numbers' AS ___;
76
SELECT count(DISTINCT catalognumber_dwc) AS count
77
FROM specimenreplicate
78
WHERE datasource_id =
79
    (SELECT party_id FROM party WHERE organizationname = :datasource)
80
;
81

    
82
SELECT 'duplicate catalog numbers' AS ___;
83
SELECT catalognumber_dwc, count(*) AS count
84
FROM specimenreplicate
85
WHERE datasource_id =
86
    (SELECT party_id FROM party WHERE organizationname = :datasource)
87
GROUP BY catalognumber_dwc
88
HAVING count(*) > 1
89
ORDER BY catalognumber_dwc NULLS FIRST/* to match MySQL */
90
;
91

    
92
SELECT '# counties' AS ___;
93
SELECT count(DISTINCT namedplace.namedplace_id) AS count
94
FROM specimenreplicate
95
JOIN taxonoccurrence USING (taxonoccurrence_id)
96
JOIN locationevent USING (locationevent_id)
97
JOIN locationdetermination USING (location_id)
98
JOIN namedplace_ancestor USING (namedplace_id)
99
JOIN namedplace
100
    ON namedplace.namedplace_id = namedplace_ancestor.ancestor_id
101
    AND namedplace.rank = 'county'
102
WHERE specimenreplicate.datasource_id =
103
    (SELECT party_id FROM party WHERE organizationname = :datasource)
104
;
(16-16/16)