Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 737 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
737 raphael 1
-- TODO:
2
-- fix référentiel: suppression n° de version et uniformisation
3
-- SELECT DISTINCT nom_referentiel, COUNT(id_observation) AS count FROM cel_obs GROUP BY nom_referentiel ORDER BY count DESC;
4
 
5
-- fix date: NULL pour les dates dans le futur
6
-- SELECT courriel_utilisateur, id_observation, date_observation FROM cel_obs WHERE date_observation > NOW();
7
 
8
 
9
 
10
DROP TABLE IF EXISTS `cel_references`;
738 raphael 11
CREATE TABLE IF NOT EXISTS `cel_references` (
737 raphael 12
       `referentiel` CHAR(5) NOT NULL, -- ENUM ("bdtfx", "bdtfx", "bdtxa", ...),
13
 
14
       -- bdtfx
15
       `num_nom` INT(9) NOT NULL DEFAULT '0',
16
       `num_nom_retenu` VARCHAR(9) DEFAULT NULL,
17
 
738 raphael 18
       -- bdtfx + nvjfl_v2007
19
       `num_taxon` int(9) NOT NULL,
20
 
21
       -- bdtfx
737 raphael 22
       `nom_sci` VARCHAR(500) NOT NULL,
23
       `auteur` VARCHAR(100) DEFAULT NULL,
24
 
738 raphael 25
 
737 raphael 26
       -- cel_obs
27
       --       `nom_ret_nn` DECIMAL(9,0) DEFAULT NULL COMMENT 'Numéro du nom retenu.',
28
       --       `nom_ret` VARCHAR(255) DEFAULT NULL,
29
 
30
       -- nvjfl_v2007 (`nom_vernaculaire` text NOT NULL)
738 raphael 31
       -- mais NULL à cause de nva
32
       `nom_commun` VARCHAR(60) NULL,
737 raphael 33
PRIMARY KEY (`referentiel`, `num_nom`)
34
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
35
 
36
 
738 raphael 37
/*
38
way 1: theory
39
INSERT INTO `cel_references` (`referentiel`, `num_nom`, `num_nom_retenu`, `nom_sci`, `auteur`, `nom_commun`) \
40
       SELECT "bdtfx", b.num_nom, b.num_nom_retenu, b.nom_sci, b.auteur, n.nom_vernaculaire, MAX(n.num_statut)	FROM bdtfx_v1_01 b LEFT JOIN nvjfl_v2007 n	ON (b.num_taxonomique = n.num_taxon AND n.code_langue = 'fra' )	GROUP BY b.num_nom \
41
       UNION \
42
       SELECT "bdtxa", b.num_nom, b.num_nom_retenu, b.nom_sci, b.auteur, n.nom_vernaculaire, NULL				FROM bdtxa_v1_00 b LEFT JOIN nva_v2013_06 n	ON (b.num_tax = n.num_taxon AND n.code_langue = 'fra' )			GROUP BY b.num_nom;
43
SELECT "isfan", b.num_nom, b.num_nom_retenu, b.nom_sci, b.auteur, NULL FROM isfan_v2013 b;
44
*/
737 raphael 45
 
46
 
738 raphael 47
/*
48
Détermination des nom vernaculaires meilleurs et uniques:
737 raphael 49
 
738 raphael 50
way 1:
51
-- SELECT n.num_taxon, n.nom_vernaculaire, n.num_statut, n2.num_statut FROM nvjfl_v2007 n LEFT JOIN nvjfl_v2007 n2 ON (n.num_taxon = n2.num_taxon) WHERE n.num_taxon < 32 AND n.code_langue = 'fra' GROUP BY n.num_taxon, n.num_statut HAVING n.num_statut = MAX(n2.num_statut) LIMIT 100;
52
-- 12311
53
-- # distinct=
737 raphael 54
 
738 raphael 55
way 2:
56
-- SELECT n.num_taxon, n.nom_vernaculaire FROM nvjfl_v2007 n INNER JOIN nvjfl_v2007 n2 ON (n.num_taxon = n2.num_taxon AND n.code_langue = n2.code_langue AND n.num_statut > n2.num_statut) WHERE n.code_langue = 'fra' GROUP BY n.num_taxon;
57
-- 2680
737 raphael 58
 
738 raphael 59
way 2":
60
-- SELECT n.num_taxon, n.nom_vernaculaire FROM nvjfl_v2007 n LEFT JOIN nvjfl_v2007 n2 ON (n.num_taxon = n2.num_taxon AND n.code_langue = n2.code_langue AND n.num_statut > n2.num_statut) WHERE n.code_langue = 'fra' AND n2.num_statut IS NOT NULL GROUP BY num_taxon;
61
-- 2680, Mais problème ensuite: SELECT n.* from cel_references NATURAL JOIN nvjfl_v2007 n WHERE `nom_commun` = '' AND n.code_langue = 'fra';
62
 
63
 
64
Note: 16146 nom communs français distincts, 12312 num_taxon fr, aucun num_statut NULL en français
65
*/
66
 
67
 
68
DROP TEMPORARY TABLE IF EXISTS `T_nvjfl_v2007`, `T_nva_v2013_06`;
69
 
737 raphael 70
CREATE TEMPORARY TABLE T_nvjfl_v2007 ( INDEX(`num_taxon`) ) AS \
738 raphael 71
       -- ( SELECT n.num_taxon, n.nom_vernaculaire FROM nvjfl_v2007 n WHERE n.code_langue = 'fra' GROUP BY n.num_taxon, n.num_statut HAVING n.num_statut = MAX(n.num_statut) );
72
       ( SELECT n.num_taxon, n.nom_vernaculaire, n.num_statut as void, MAX(n.num_statut) as void2 FROM nvjfl_v2007 n WHERE n.code_langue = 'fra' GROUP BY n.num_taxon HAVING n.num_statut = MAX(n.num_statut) );
737 raphael 73
 
738 raphael 74
-- table temporaire uniquement parce qu'il manque un index-key, autrement le LEFT JOIN ci-dessous est bien trop long
737 raphael 75
CREATE TEMPORARY TABLE T_nva_v2013_06 ( INDEX(`num_taxon`) ) AS \
738 raphael 76
       ( SELECT n.num_taxon, n.nom_vernaculaire FROM nva_v2013_06 n WHERE n.code_langue = 'fra' /* DB pb */ AND n.num_taxon IS NOT NULL /* /DB pb */ GROUP BY n.num_nom); -- aggrégat arbitraire car pas de num_statut
737 raphael 77
 
78
 
738 raphael 79
INSERT INTO `cel_references` (`referentiel`, `num_nom`, `num_nom_retenu`, `num_taxon`, `nom_sci`, `auteur`, `nom_commun`) \
80
       SELECT "bdtfx", b.num_nom, b.num_nom_retenu, b.num_taxonomique, b.nom_sci, b.auteur, n.nom_vernaculaire	FROM bdtfx_v1_01 b LEFT JOIN T_nvjfl_v2007 n ON (b.num_taxonomique = n.num_taxon ) \
737 raphael 81
       UNION \
738 raphael 82
       SELECT "bdtxa", b.num_nom, b.num_nom_retenu, b.num_tax, b.nom_sci, b.auteur, n.nom_vernaculaire FROM bdtxa_v1_00 b LEFT JOIN T_nva_v2013_06 n ON (b.num_tax = n.num_taxon);
83
 
84
DROP TEMPORARY TABLE IF EXISTS `T_nvjfl_v2007`, `T_nva_v2013_06`;