Bonjour a tous. moi j'ai fais une query qui permet de calculer les jour qui passent entre la premiere date de dimission de l'hopital à la premiere date qui une personne rentre.

ex:


nom prenom data_ingr date_dim date_ingr_succ j rep_dim
x x 01/01/09 05/01/09 20/01/09 15 3201
x x 20/01/09 24/01/09 3201
y y 02/05/09 15/05/09 19/05/09 4 4021
y y 19/05/09 25/05/09 28/05/09 3 4021
y y 28/05/09 01/06/09 3021
z z 04/03/09 20/03/09 5401


voila ma query

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SELECT * FROM
(
SELECT
    cod_fisc,
	cognome,
	nome,
    data_ingr,
    data_dim, rep_ingr, rep_dim,
    lead(data_ingr,'1') over (partition BY cod_fisc ORDER BY data_dim) AS data_ingr_succ,
    lead(data_ingr,'1') over (partition BY cod_fisc ORDER BY data_dim) - s.DATA_INGR AS giorni,
    h.descr, cat_0, tipo_ricov
FROM
    report_sdo s, reparti_hsp h      
WHERE
 h.cod_rep = s.rep_ingr and anno = '2007'  
)
where giorni is not null and giorni between 0 and 31
order by  cognome, GIORNI
mon probleme: comment je fais pour sortir seulement les personnes qui sont rentrees à l'hopital dans le meme rep_dim de la premiere sortie?

c'est a dire:

nom prenom data_ingr date_dim date_ingr_succ j rep_dim
x x 01/01/09 05/01/09 20/01/09 15 3201
x x 20/01/09 24/01/09 3201
y y 02/05/09 15/05/09 19/05/09 4 4021
y y 19/05/09 25/05/09 28/05/09 3 4021