wiki:Recette SQL SommeEffectifs

Recette pour calculer les effectifs migrants par espèce

Retour à Recette SQL


Note : ces exemples sont compatibles avec la version 0.3 du logiciel ...


Somme des effectifs du genre Alose sur notre passe à bassins

(allez voir les codes dans la table ref.tr_taxon_tax)

select sum(s.lot_effectif),s.annee,s.mois from(
select *, extract(month from ope_date_debut) as mois,extract(year from ope_date_debut) as annee from  iav.vue_lot_ope_car 
where lot_tax_code='2055'
and ope_dic_identifiant=5
) as s
group by s.annee,s.mois
order by s.annee,s.mois
419964
2119965
2119966
119967
219973
6419974
9319975
1619976
919977
119979


Somme des effectifs d'anguilles en fonction du devenir de lot entre 2002 et 2006

select sum(s.lot_effectif) as Effectif,s.annee as Annee,s.dev_libelle as Devenir from(
select *, extract(year from ope_date_debut) as annee from  iav.vue_lot_ope_car 
where lot_tax_code='2038' --anguille
and ope_dic_identifiant=6 --passe à anguille
and ope_date_debut > '2002-01-01 00:00:00'
and ope_date_debut < '2006-01-01 00:00:00'
) as s
group by s.annee,s.dev_libelle
order by s.annee,s.dev_libelle
EffectifAnneeDevenir
337862002Relâché au droit de la station
992002Trépassé
291632003Relâché au droit de la station
42003Trépassé
165032004Relâché au droit de la station
412004Trépassé
29972005Relâché au droit de la station
1612005Trépassé
142005


Liste des taxons ayant fréquenté la passe entre 2005 et 2006

select distinct on (tax_nom_latin) tax_nom_latin as Taxon from iav.vue_lot_ope_car 
where ope_dic_identifiant=5
and ope_date_debut > '2005-01-01 00:00:00'
and ope_date_debut < '2006-01-01 00:00:00'
order by Taxon
Alosa
Anguilla anguilla
Dicentrarchus labrax
Liza ramada
Petromyzon marinus
Salmo


Comparaison des effectifs de taxons de deux dispositifs de comptage

note : j'ai que des anguilles dans le dc6 et le symétrique ne marche pas (il me manque des noms de taxons)

Select taxon, effectifdc5,effectifdc6 FROM(
        select tax_nom_latin,
         sum (lot_effectif) as effectifdc6 
         FROM iav.vue_lot_ope_car v1
         WHERE ope_dic_identifiant=6
         AND ope_date_debut > '2007-01-01 00:00:00'
         AND ope_date_debut < '2008-01-01 00:00:00'
         GROUP BY tax_nom_latin) as sub1
FULL OUTER JOIN
         (select tax_nom_latin as taxon,
         sum(lot_effectif)  as effectifdc5
         FROM iav.vue_lot_ope_car v2 
         WHERE ope_dic_identifiant=5
         AND ope_date_debut > '2007-01-01 00:00:00'
         AND ope_date_debut < '2008-01-01 00:00:00'
         GROUP BY tax_nom_latin) as sub2
On sub2.taxon = sub1.tax_nom_latin;
taxoneffectifDC5effectifDC6
Alosa1112
Anguilla anguilla2819652
Ctenopharyngodon idellus8
Cyprinus carpio6
Petromyzon marinus115
Salmo1
Silurus glanis3
Tinca tinca1


Somme des effectifs de civelles sur les deux passes du barrage d'Arzal par mois et années

/*
requete complete
*/
with lot_ope_detail as (
SELECT t_operation_ope.ope_identifiant, t_lot_lot.lot_identifiant, t_operation_ope.ope_dic_identifiant, 
t_lot_lot.lot_lot_identifiant AS lot_pere, t_operation_ope.ope_date_debut, t_operation_ope.ope_date_fin, 
t_lot_lot.lot_effectif, t_lot_lot.lot_quantite, t_lot_lot.lot_tax_code, t_lot_lot.lot_std_code, tr_taxon_tax.tax_nom_latin, 
tr_stadedeveloppement_std.std_libelle, tr_devenirlot_dev.dev_code, tr_devenirlot_dev.dev_libelle
   FROM iav.t_operation_ope
   JOIN iav.t_lot_lot ON t_lot_lot.lot_ope_identifiant = t_operation_ope.ope_identifiant
   LEFT JOIN ref.tr_typequantitelot_qte ON tr_typequantitelot_qte.qte_code::text = t_lot_lot.lot_qte_code::text
   LEFT JOIN ref.tr_devenirlot_dev ON tr_devenirlot_dev.dev_code::text = t_lot_lot.lot_dev_code::text
   JOIN ref.tr_taxon_tax ON tr_taxon_tax.tax_code::text = t_lot_lot.lot_tax_code::text
   JOIN ref.tr_stadedeveloppement_std ON tr_stadedeveloppement_std.std_code::text = t_lot_lot.lot_std_code::text)
select * from lot_ope_detail


/*
Somme des effectifs de civelles sur les deux passes d'Arzal par mois
*/

with lot_ope_detail as (
SELECT t_operation_ope.ope_identifiant, t_lot_lot.lot_identifiant, t_operation_ope.ope_dic_identifiant, 
t_lot_lot.lot_lot_identifiant AS lot_pere, t_operation_ope.ope_date_debut, t_operation_ope.ope_date_fin, 
t_lot_lot.lot_effectif, t_lot_lot.lot_quantite, t_lot_lot.lot_tax_code, t_lot_lot.lot_std_code, tr_taxon_tax.tax_nom_latin, 
tr_stadedeveloppement_std.std_libelle, tr_devenirlot_dev.dev_code, tr_devenirlot_dev.dev_libelle
   FROM iav.t_operation_ope
   JOIN iav.t_lot_lot ON t_lot_lot.lot_ope_identifiant = t_operation_ope.ope_identifiant
   LEFT JOIN ref.tr_typequantitelot_qte ON tr_typequantitelot_qte.qte_code::text = t_lot_lot.lot_qte_code::text
   LEFT JOIN ref.tr_devenirlot_dev ON tr_devenirlot_dev.dev_code::text = t_lot_lot.lot_dev_code::text
   JOIN ref.tr_taxon_tax ON tr_taxon_tax.tax_code::text = t_lot_lot.lot_tax_code::text
   JOIN ref.tr_stadedeveloppement_std ON tr_stadedeveloppement_std.std_code::text = t_lot_lot.lot_std_code::text)

select  sum(s.lot_quantite),s.annee,s.mois from(
select *, extract(month from ope_date_debut) as mois,extract(year from ope_date_debut) as annee  from lot_ope_detail
where lot_tax_code='2038'
and (ope_dic_identifiant=6 or ope_dic_identifiant=12)
and lot_quantite is not null
and lot_std_code='CIV'
) as s
group by s.annee,s.mois
order by s.annee,s.mois

Last modified 8 years ago Last modified on Dec 14, 2016 3:15:01 PM