Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2082 connectés 

  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  correlated subquery

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

correlated subquery

n°1685372
johnny1234
Posté le 12-02-2008 à 15:32:44  profilanswer
 

Bonjour, j'ai besoin d'un coup de pouce car je bloque. :cry:  
 
Je dois utiliser une 'correlated subquery'.
Je dois créer une requête qui retournera tous les clients qui ont une limite de credit égal ou inférieur à la somme des commandes clients.
 
 
Actuellement, j'affiche tout :
 
select c.customer_id as id,
c.name,
c.credit_limit as limit,
sum(s.total) as spent
from customer c,
sales_order s
where c.customer_id = s.customer_id
group by c.customer_id, c.name, c.credit_limit;
 
      ID NAME                                               LIMIT      SPENT
---------- --------------------------------------------- ---------- ----------
       106 SHAPE UP                                      6000     9076.8
       228 FITNESS FIRST                               4000       7101
       204 THE POWER FORWARD                     12000    15071.4
       208 AL AND BOB'S SPORTS                       4000    21119.8
 
 
Ca affiche tout alors que je dois afficher que ceux qui ne dépasse pas leur limite de crédit avec 'correlated subquery'.
 
Je ne sais pas trop comment faire la suite.
 
Merci pour votre aide.

mood
Publicité
Posté le 12-02-2008 à 15:32:44  profilanswer
 

n°1685382
anapajari
s/travail/glanding on hfr/gs;
Posté le 12-02-2008 à 15:42:32  profilanswer
 

Apres ton group

Code :
  1. HAVING c.credit_limit >= sum(s.total)


---------------
Software and cathedrals are much the same - first we build them, then we pray.
n°1685394
johnny1234
Posté le 12-02-2008 à 15:56:29  profilanswer
 

j'ai trouvé !!
 
select c.customer_id as id,
c.name,
c.credit_limit as limit,
sum(s.total) as spent
from customer c,
sales_order s
where c.customer_id=s.customer_id
group by c.customer_id, c.name, c.credit_limit
having sum(s.total)<=
        (select cr.credit_limit
        from customer cr
        where cr.customer_id=c.customer_id);

n°1685413
anapajari
s/travail/glanding on hfr/gs;
Posté le 12-02-2008 à 16:16:43  profilanswer
 

johnny1234 a écrit :

j'ai trouvé !!
 
select c.customer_id as id,
c.name,
c.credit_limit as limit,
sum(s.total) as spent
from customer c,
sales_order s
where c.customer_id=s.customer_id
group by c.customer_id, c.name, c.credit_limit
having sum(s.total)<=
        (select cr.credit_limit
        from customer cr
        where cr.customer_id=c.customer_id);


[:prozac] s'quoi l'interêt de la subquery dans ton having ?


---------------
Software and cathedrals are much the same - first we build them, then we pray.

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  correlated subquery

 

Sujets relatifs
[ADO.NET] Requete sur dataset avec subquery[MySQL] Cherche 3eme dan Optimisation: requette avec SubQuery correlée
Postgresql 8.0 et contraintes d'intégrités avec subquery[Postgresql] requete avec une subquery...
Plus de sujets relatifs à : correlated subquery


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR