Echantillon de résultats

Pour récupérer un échantillon d’une table, utiliser la fonction first_value.

SELECT system_coord, codepc
FROM reflet_05.pc_localisation
WHERE codepc IN
(
SELECT first_value(codepc) over(partition BY system_coord ORDER BY codepc) FROM reflet_05.pc_localisation
);

Remonte pour chaque système de coordonnées de la table un PC.

Autre exemple, pour remonter pour chaque RCRAT un seul DSLAM :

select
    r.code "rcrat"
    , r.code_dr "dr"
    , d.code "dslam"
from
    dslam d
    , rcrat r
where
    d.code in (select first_value(code) over(partition by id_rcrat order by code) from dslam where type_dslam = 'FULL_GE')
and d.id_rcrat = r.id
and d.type_dslam = 'FULL_GE'
order by 1, 2, 3
;

Laisser un commentaire