Oracle sql

Résolu/Fermé
pacman77 - 11 déc. 2007 à 11:36
phil232 Messages postés 607 Date d'inscription mardi 25 septembre 2007 Statut Membre Dernière intervention 31 janvier 2008 - 11 déc. 2007 à 16:09
bonjour,
je souhaite faire une requête qui, dans la clause select, utilise comme colonne des sous-interrogation scalaire. Je retrouve les bonnes informations, seulement celles-ci sont dupliquées.
Il s'agit, à partir de ces 2 tables, afficher les ventes effectuées pour chaque client et pour chacun des 4 trimestres de l'année.

mes tables:
sales_order(ORDER_ID ,ORDER_DATE,CUSTOMER_ID,TOTAL)
customer(CUSTOMER_ID,CREDIT_LIMIT)

ma requête:

select distinct c.name as "name",
so1.total as "1st",
so2.total as "2nd",
so3.total as "3rd",
so4.total as "4th"
from customer c, sales_order s,sales_order so1,sales_order so2,sales_order so3,sales_order so4
where c.customer_id=s.customer_id
and so1.total in (select so1.total from sales_order so1 where so1.customer_id=c.customer_id and to_char(so1.order_date, 'Q')=1)
and so2.total in (select so2.total from sales_order so2 where so2.customer_id=c.customer_id and to_char(so2.order_date, 'Q')=2)
and so3.total in (select so3.total from sales_order so3 where so3.customer_id=c.customer_id and to_char(so3.order_date, 'Q')=3)
and so4.total in (select so4.total from sales_order so4 where so4.customer_id=c.customer_id and to_char(so4.order_date, 'Q')=4)
order by c.name;

merci pour votre aide
A voir également:

3 réponses

phil232 Messages postés 607 Date d'inscription mardi 25 septembre 2007 Statut Membre Dernière intervention 31 janvier 2008 178
11 déc. 2007 à 14:17
peut-tu essayer ça :

select distinct c.name as "name",
s.total as "1st",
NULL as "2nd",
NULL as "3rd",
NULL as "4th"
from customer c, INNER JOIN sales_order s ON c.customer_id=s.customer_id
WHERE to_char(s.order_date, 'Q')=1
UNION
select distinct c.name as "name",
NULL as "1st",
s.total as "2nd",
NULL as "3rd",
NULL as "4th"
from customer c, INNER JOIN sales_order s ON c.customer_id=s.customer_id
WHERE to_char(s.order_date, 'Q')=2
UNION
select distinct c.name as "name",
NULL as "1st",
NULL as "2nd",
s.total as "3rd",
NULL as "4th"
from customer c, INNER JOIN sales_order s ON c.customer_id=s.customer_id
WHERE to_char(s.order_date, 'Q')=3
UNION
select distinct c.name as "name",
NULL as "1st",
NULL as "2nd",
NULL as "3rd",
s.total as "4th"
from customer c, INNER JOIN sales_order s ON c.customer_id=s.customer_id
WHERE to_char(s.order_date, 'Q')=4
1
merci beaucoup, je ne pensais pas utiliser Inner join mais ça marche!! :-)
0
phil232 Messages postés 607 Date d'inscription mardi 25 septembre 2007 Statut Membre Dernière intervention 31 janvier 2008 178
11 déc. 2007 à 16:09
tu peut le reécrire avec un WHERE pourquoi pas ?

il m'a fallu qq années mais maintenant je ne veux plus changer
0