j'ai un souci pour créer une requete qui pourtant ne parait pas trop compliquée. Le contexte est le suivant :
j'ai 3 tables : societe, incident, contrat
Je souhaite connaitre la liste des societes chez qui le contrat est actif et chez qui il n'y a eu aucun incident depuis 365 jours.
Le champ NO_SOCIETE est présent dans les 3 tables.
Table SOCIETE
NO_SOCIETE, NO_SOCIETE
Table CONTRAT
NO_SOCIETE, COD_ETAT
Table INCIDENT
NO_SOCIETE, CREER_LE
J'ai essayé ça mais ça ne correspond pas :
select NO_SOCIETE,NOM from societe
where not exists
(
select * from incident
where (incident.NO_SOCIETE=societe.NO_SOCIETE)
and (incident.CREER_LE < DATEADD(day,-365,getdate()))
)
and exists
(select * from CONTRAT
where (contrat.NO_SOCIETE=societe.NO_SOCIETE)
and (contrat.COD_ETAT='01')
)
Merci d'avance pour vos réponses.
Jujunio.