Skip to content

Requête SQL pour export #6

@Adisser

Description

@Adisser

@zoometh Voici une base de requête SQL pour servir de base à une fonction d'export sous format tabulaire :

SELECT
    s.nom_site AS "context_name",
    s.nom_place AS "place_name",
    s.date_debut AS "start_date",
    s.date_fin AS "end_date",
    e.nom_ech AS "sample_name",

    (COALESCE(typo.categorie_en, '') || ' ' ||
	 COALESCE(typo.sous_categorie_en, '') || ' ' ||
	 COALESCE(typo.materiau_en, '')) AS typology,

    c.id_chips AS "chips_id",
    c.carbon AS c,
    c.n, c.o, c.na, c.mg, c.al, c.si, c.p, c.s, c.cl, c.k, c.ca, c.mn, c.fe,
    c.perte_feu AS "loss on ignition",
    c.ag, c.ar, c.arsenic AS "as", c.au, c.b, c.ba, c.be, c.bi, c.br,
    c.cd, c.ce, c.co, c.cr, c.cs, c.cu, c.dy, c.er, c.eu, c.f,
    c.delta56fe AS deltafe56,
    c.delta57fe AS deltafe57,
    c.ga, c.gd, c.ge, c.h, c.he, c.hf, c.hg, c.ho, c.i,
    c.indium AS "in", c.ir, c.kr, c.la, c.li, c.lu, c.mo, c.nb, c.nd, c.ni,
    c.os_ppt AS os,
    c.os187_os188,
    c.os187_os186,
    c.pb, c.pd, c.pr, c.pt, c.rb, c.re, c.rh, c.ru, c.sb, c.sc, c.se,
    c.sm, c.sn, c.sr, c.sr87_sr86, c.ta, c.tb, c.tc, c.te, c.th, c.ti,
    c.tl, c.tm, c.u, c.v, c.w, c.xe, c.y, c.yb, c.zn, c.zr,

    m.methode_analyse AS major_method,
    (m.laboratoire || ' - ' || m.marque || ' ' || m.modele) AS major_analytical_setup,
    m.methode_analyse AS trace_method,
    (m.laboratoire || ' - ' || m.marque || ' ' || m.modele) AS trace_analytical_setup,

    (
        COALESCE(l.authors, '') || ' (' || COALESCE(l.pub_year::text, '') || '), '
        || COALESCE(l.title, '') || ', '
        || COALESCE(l.journal_book, '') || ', '
        || COALESCE(l.volume::text, '')
    ) AS reference,

    l.url,
    s.longitude,
    s.latitude,

    typo.filiere_en AS process,
    typo.contexte_en AS "operation",
    typo.categorie_en AS category,
    typo.sous_categorie_en AS subcategory

FROM chips c
JOIN echantillons e ON c.id_ech = e.id_ech
JOIN sites s ON e.id_site = s.id_site
JOIN typo ON e.id_typo = typo.id_typo
JOIN personnes p ON e.referent = p.id_personne
JOIN gadm g ON s.id_localite = g.uid
JOIN machines m ON c.id_machinem = m.id_dispositif
JOIN literature l ON c.bibreference = l.id_lit

WHERE c.open = TRUE

ORDER BY s.nom_site, e.nom_ech) 
TO 'C:\Users\Public\example.csv' DELIMITER ';' ENCODING 'UTF-8' CSV HEADER;```

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions