Bonjour,
J'ai une base de données qui contient une table d'historisation des contacts où il y a plusieurs lignes d'historisation de contacts pour un même identifiant de contrat.
Je souhaiterais dans une vue récupérer les données de plusieurs lignes de contact communes avec le même identifiant de contrat:
CONTACT_HIST_IM_ID est l'identifiant du contrat
J'ai effectué une query qui permet de récupérer tous les noms associés à un contrat mais les noms sont en double et j'aimerais avoir les noms qu'une seule fois:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 SELECT im_id, SUBSTR(SYS_CONNECT_BY_PATH(contact_name, ', '),2) contact_name FROM (SELECT DISTINCT(CONTACT_NAME), CONTACT_HIST_IM_ID as im_id, COUNT(*) OVER ( partition BY CONTACT_HIST_IM_ID ) im, ROW_NUMBER () OVER ( partition BY CONTACT_HIST_IM_ID order by contact_name) seq FROM FIDES_CONTACT_HIST_V WHERE CONTACT_HIST_IM_ID IS NOT NULL ) WHERE seq =im START WITH seq =1 CONNECT BY prior seq+1=seq AND prior im_id =im_id;
IM_ID CONTACT_NAME 39 Constantin-Alin, Constantin-Alin, Constantin-Alin, Constantin-Alin, Constantin-Alin, Constantin-Alin, Constantin-Alin, Constantin-Alin, Constantin-Alin, Constantin-Alin, Georges, Georges, Georges, Georges, Georges, Georges, Georges, Georges, Georges, Georges, Maurizio, Maurizio, Maurizio, Maurizio, Maurizio, Maurizio, Maurizio, Maurizio, Maurizio, Maurizio, Michel, Michel, Michel, Michel, Michel, Michel, Michel, Michel, Michel, Michel, Mohammad Reza, Mohammad Reza, Mohammad Reza, Mohammad Reza, Mohammad Reza, Mohammad Reza, Mohammad Reza, Mohammad Reza, Mohammad Reza, Mohammad Reza, Pal, Pal, Pal, Pal, Pal, Pal, Pal, Pal, Pal, Pal
Pourriez-vous m'aider à éviter les doublons car je ne sais pas comment faire même avec un DISTINCT ?
Partager