Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[Oracle] double jointure externe des deux cotés

2 réponses
Avatar
Pif
Bonjour, j'ai 2 tables :

1) LigneFacturation(id_operation, montant_facture,date_facture)
2) LignePaiement(id_operation, montant_paiement, date_paiement)

je voudrais pour chaque op=E9ration obtenir le total par mois des
paiements et des facturations...

donc je voudrais faire une jointure ouverte "double" dans une requete
genre :

select * from
(select id_operation, montant_facture, to_char(date_facture,'MM') as
mois
from lignefacturation
group by id_operation, to_char(date_facture, 'MM') ) fact
join
(select id_operation, montant_paiement, to_char(date_paiement,'MM') as
mois
from LignePaiement
group by id_operation, to_char(date_paiement, 'MM') ) paie
on fact.id_operation (+) =3D paie..id_operation (+) and fact.mois (+) =3D
paie.mois (+)

bien sur, cette syntaxe ne marche pas !

Merci pour votre aide.

2 réponses

Avatar
Guillaume
Pif a écrit :
Bonjour, j'ai 2 tables :

1) LigneFacturation(id_operation, montant_facture,date_facture)
2) LignePaiement(id_operation, montant_paiement, date_paiement)

je voudrais pour chaque opération obtenir le total par mois des
paiements et des facturations...

donc je voudrais faire une jointure ouverte "double" dans une requete
genre :

select * from
(select id_operation, montant_facture, to_char(date_facture,'MM') as
mois
from lignefacturation
group by id_operation, to_char(date_facture, 'MM') ) fact
join
(select id_operation, montant_paiement, to_char(date_paiement,'MM') as
mois
from LignePaiement
group by id_operation, to_char(date_paiement, 'MM') ) paie
on fact.id_operation (+) = paie..id_operation (+) and fact.mois (+) > paie.mois (+)

bien sur, cette syntaxe ne marche pas !

Merci pour votre aide.



Bonjour,

J'essaierai de faire une requête dans le genre :

select id_operation,
mois,
sum(decode(type,'facture',montant_facture,0)) total_facture,
sum(decode(type,'paiement',montant_paiement,0)) total_paiement
from (
select 'facture' as type, id_operation, to_char(date_facture,'MMYYYY')
as mois, montant_facture
union all
select 'paiement' as type, id_operation, to_char(date_paiement,'MMYYYY')
as mois, montant_paiement
)
group by id_operation, mois;

Concernant les jointures externes à double sens, depuis la version 9 ou
10 Oracle accepte la syntaxe "FULL OUTER JOIN".

Cordialement.

Guillaume
Avatar
Serguei Tarassov
On 29/01/2010 14:23, Pif wrote:
Bonjour, j'ai 2 tables :

1) LigneFacturation(id_operation, montant_facture,date_facture)
2) LignePaiement(id_operation, montant_paiement, date_paiement)

je voudrais pour chaque opération obtenir le total par mois des
paiements et des facturations...

donc je voudrais faire une jointure ouverte "double" dans une requete
genre :

select * from
(select id_operation, montant_facture, to_char(date_facture,'MM') as
mois
from lignefacturation
group by id_operation, to_char(date_facture, 'MM') ) fact
join
(select id_operation, montant_paiement, to_char(date_paiement,'MM') as
mois
from LignePaiement
group by id_operation, to_char(date_paiement, 'MM') ) paie
on fact.id_operation (+) = paie..id_operation (+) and fact.mois (+) > paie.mois (+)

bien sur, cette syntaxe ne marche pas !

Merci pour votre aide.



Utilise le syntaxe ANSI SQL standard avec FULL OUTER JOIN.

select *
from
LigneFacturation F
full outer join
LignePaiement P
on
F.id_operation = P.id_operation
and F.mois = P.mois


A+
Serguei TARASSOV
MCITP SQL Server Dev/DBA
http://sgbd.arbinada.com