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

  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  Problème de requete

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Problème de requete

n°1314162
isa21493
Posté le 27-02-2006 à 11:24:00  profilanswer
 

bonjour à tous,  
 
voici un exemple de ce que je fais et de ce que je veux:  
 
j'ai une table "bugs":  
 
name: ------------ id  
 
bug 1 -------------- 1  
bug 1 -------------- 1  
bug 2 -------------- 3  
bug 3 -------------- 1  
bug 4 -------------- 1  
 
ma requete est la suivante:  

Code :
  1. SELECT bugs.name, Count(bugs.id) AS CompteDeid
  2. FROM bugs
  3. WHERE (((bugs.id)=1))
  4. GROUP BY bugs.name;


 
là je récupère ceci:  
 
bug 1 -------------- 2  
bug 3 -------------- 1  
bug 4 -------------- 1  
 
et moi ce que je voudrais c'est  
 
bug 1 -------------- 2  
bug 2 -------------- 0  
bug 3 -------------- 1  
bug 4 -------------- 1  
 
je ne peux pas utiliser de jointure puisque c'est dans la meme table.  
 
savez vous comment faire?

mood
Publicité
Posté le 27-02-2006 à 11:24:00  profilanswer
 

n°1314184
anapajari
s/travail/glanding on hfr/gs;
Posté le 27-02-2006 à 11:39:32  profilanswer
 

isa21493 a écrit :


ma requete est la suivante:  

Code :
  1. SELECT bugs.name, Count(bugs.id) AS CompteDeid
  2. FROM bugs
  3. WHERE bugs.id=1
  4. GROUP BY bugs.name;




C'est normal que "bug 2" ne soit pas remonté il a un id=3 et dans ta requete tu fais un  

Code :
  1. where bug.id=1


Enleve le where et tu auras tout tes résultats ...
 
 

isa21493 a écrit :


je ne peux pas utiliser de jointure puisque c'est dans la meme table.  


tu n'en as pas besoin mais il est tout a fait possible de jointer une table sur elle-même...

n°1314201
isa21493
Posté le 27-02-2006 à 11:50:28  profilanswer
 

en fait mon where est normal
 
je veux faire le compte des bugs ayant eu lieu sur le projet n°1 (pas dans le 3)
 
et donc je voudrais que pour le bug 2, le résultat soit 0 car ya un bug 2 mais dans le projet 3 alors qu'il n'y en a pas dans le projet 1
 
si j'enleve le where j'ai les résultats pour tous les projets, ce n'est pas ce que je veux
 

n°1314212
anapajari
s/travail/glanding on hfr/gs;
Posté le 27-02-2006 à 12:02:51  profilanswer
 

si j'ai tout compris tu veux remonter tous les bugs ayant un "id projet" égal 1 même ceux qui existent pas?
 
Comment définis tu "ceux qui n'existent pas"? C'est ceux qui sont présents dans la table mais avec un autre id projet?

n°1314218
isa21493
Posté le 27-02-2006 à 12:12:29  profilanswer
 

ceux qui n'existent pas ce sont ceux qui existent dans la table mais qui n'ont pas d'id = 1

n°1314266
rufo
Pas me confondre avec Lycos!
Posté le 27-02-2006 à 13:22:06  profilanswer
 

Et en faisant un JOIN LEFT sur la même table? Ca donnerait quoi?

n°1314271
anapajari
s/travail/glanding on hfr/gs;
Posté le 27-02-2006 à 13:27:59  profilanswer
 

essaye un truc comme ça pour voir:

Code :
  1. SELECT
  2. allPrj.name,
  3. Count(curPrj.id) AS CompteDeid
  4. FROM
  5. bugs as allPrj
  6. left outer join bugs as curPrj on ( allPrj.name = curPrj.name and curPrj.id = 1)
  7. GROUP BY
  8. allPrj.name;

n°1314276
skeye
Posté le 27-02-2006 à 13:33:54  profilanswer
 

Solution bête et méchante :
 

Code :
  1. SELECT name, Count(id) AS CompteDeid
  2. FROM bugs
  3. WHERE id = 1
  4. GROUP BY name
  5. UNION
  6. SELECT name, 0 AS CompteDeid
  7. FROM bugs
  8. WHERE id != 1


 
[:doc petrus]

Message cité 1 fois
Message édité par skeye le 27-02-2006 à 13:34:19

---------------
Can't buy what I want because it's free -
n°1314281
anapajari
s/travail/glanding on hfr/gs;
Posté le 27-02-2006 à 13:39:15  profilanswer
 

skeye a écrit :

Solution bête et méchante :
 

Code :
  1. SELECT name, Count(id) AS CompteDeid
  2. FROM bugs
  3. WHERE id = 1
  4. GROUP BY name
  5. UNION
  6. SELECT name, 0 AS CompteDeid
  7. FROM bugs
  8. WHERE id != 1


 
[:doc petrus]


 
Oui mais :D
si tu un "name" présent pour id=1 et id!=1 tu te retrouves dans les résultats avec deux fois ce "name" une fois à X et une fois à 0...
Ou alors faut faire péter un not exist  dans la 2eme requete!

n°1314286
skeye
Posté le 27-02-2006 à 13:42:32  profilanswer
 

anapajari a écrit :

Oui mais :D
si tu un "name" présent pour id=1 et id!=1 tu te retrouves dans les résultats avec deux fois ce "name" une fois à X et une fois à 0...
Ou alors faut faire péter un not exist  dans la 2eme requete!


 
ah oui, un peu trop bête, sur le coup.[:god]
'fin bref, on voit l'idée, quoi...[:joce]


---------------
Can't buy what I want because it's free -
mood
Publicité
Posté le 27-02-2006 à 13:42:32  profilanswer
 

n°1314305
isa21493
Posté le 27-02-2006 à 13:57:32  profilanswer
 

merci pour votre aide
mais je me perds dans ma requete:
 
en fait la mienne est plus compliquée:
 
code:
 
SELECT table_custom_field_string_table_0.value AS 'Area', Count(table_custom_field_string_table_0.bug_id) AS 'Current'
 
FROM base.table_bug_table table_bug_table_0, base.table_custom_field_string_table table_custom_field_string_table_0
 
WHERE (table_bug_table_0.project_id=8) AND (table_bug_table_0.category='bug') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=19) AND (table_bug_table_0.category='bug') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=20) AND (table_bug_table_0.category='bug') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=8) AND (table_bug_table_0.category='support') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=19) AND (table_bug_table_0.category='support') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=20) AND (table_bug_table_0.category='support') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=8) AND (table_bug_table_0.category='correction') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=19) AND (table_bug_table_0.category='correction') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=20) AND (table_bug_table_0.category='correction') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id)
 
GROUP BY table_custom_field_string_table_0.value
 
 
 

n°1314308
skeye
Posté le 27-02-2006 à 13:59:45  profilanswer
 

euh, t'as pas un moyen plus simple d'écrire ça? [:pingouino]
Ca m'a l'air de beaucoup se répéter, tout ça...:/


---------------
Can't buy what I want because it's free -
n°1314310
isa21493
Posté le 27-02-2006 à 14:00:47  profilanswer
 

Code :
  1. SELECT table_custom_field_string_table_0.value AS 'Area', Count(table_custom_field_string_table_0.bug_id) AS 'Current'
  2. FROM base.table_bug_table table_bug_table_0, base.table_custom_field_string_table table_custom_field_string_table_0
  3. WHERE (table_bug_table_0.project_id=8) AND (table_bug_table_0.category='bug') AND
  4. (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=19) AND (table_bug_table_0.category='bug') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=20) AND (table_bug_table_0.category='bug') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=8) AND (table_bug_table_0.category='support') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=19) AND (table_bug_table_0.category='support') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=20) AND (table_bug_table_0.category='support') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=8) AND (table_bug_table_0.category='correction') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=19) AND (table_bug_table_0.category='correction') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=20) AND (table_bug_table_0.category='correction') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND (table_bug_table_0.id=table_custom_field_string_table_0.bug_id)
  5. GROUP BY table_custom_field_string_table_0.value


 
je récupère ceci:
 
area: ---------- current:
nord ----------- 10
sud ------------ 5
est  ------------ 1
 
et je voudrais  
 
area: ---------- current:
nord ----------- 10
sud ------------ 5
est  ------------ 1
ouest ----------- 0
 
 
ces 2 champs font parties de la meme table mais j'ai une autre table avec une jointure où je fais des where

n°1314312
isa21493
Posté le 27-02-2006 à 14:02:54  profilanswer
 

Code :
  1. SELECT table_custom_field_string_table_0.value AS 'Area', Count(table_custom_field_string_table_0.bug_id) AS 'Current'
  2. FROM base.table_bug_table table_bug_table_0, base.table_custom_field_string_table table_custom_field_string_table_0
  3. WHERE (table_bug_table_0.project_id=8) AND (table_bug_table_0.category='bug') AND
  4. (table_bug_table_0.status<>80 And table_bug_table_0.status<>90) AND (week
  5. (table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)=YEAR(NOW
  6. ())) AND (table_custom_field_string_table_0.field_id=1) AND
  7. (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=19) AND
  8. (table_bug_table_0.category='bug') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90)
  9. AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)
  10. =YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND
  11. (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=20) AND
  12. (table_bug_table_0.category='bug') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90)
  13. AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)
  14. =YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND
  15. (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=8) AND
  16. (table_bug_table_0.category='support') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90)
  17. AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)
  18. =YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND
  19. (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=19) AND
  20. (table_bug_table_0.category='support') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90)
  21. AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)
  22. =YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND
  23. (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=20) AND
  24. (table_bug_table_0.category='support') AND (table_bug_table_0.status<>80 And table_bug_table_0.status<>90)
  25. AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR(table_bug_table_0.last_updated)
  26. =YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND
  27. (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=8) AND
  28. (table_bug_table_0.category='correction') AND (table_bug_table_0.status<>80 And
  29. table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR
  30. (table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND
  31. (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=19) AND
  32. (table_bug_table_0.category='correction') AND (table_bug_table_0.status<>80 And
  33. table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR
  34. (table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND
  35. (table_bug_table_0.id=table_custom_field_string_table_0.bug_id) OR (table_bug_table_0.project_id=20) AND
  36. (table_bug_table_0.category='correction') AND (table_bug_table_0.status<>80 And
  37. table_bug_table_0.status<>90) AND (week(table_bug_table_0.last_updated,7)=week(NOW(),7)) AND (YEAR
  38. (table_bug_table_0.last_updated)=YEAR(NOW())) AND (table_custom_field_string_table_0.field_id=1) AND
  39. (table_bug_table_0.id=table_custom_field_string_table_0.bug_id)
  40. GROUP BY table_custom_field_string_table_0.value


n°1314313
isa21493
Posté le 27-02-2006 à 14:04:21  profilanswer
 

ben en fait ça s'écrit comme ça automatiquement dans MS Query

n°1314327
anapajari
s/travail/glanding on hfr/gs;
Posté le 27-02-2006 à 14:10:41  profilanswer
 

skeye a écrit :

euh, t'as pas un moyen plus simple d'écrire ça? [:pingouino]
Ca m'a l'air de beaucoup se répéter, tout ça...:/


+1 ... enfin +28 même là ... c'est vraiment immonde [:vomi2]
 
A mon avis tu pourras pas tout faire en une seule requête ( bien que la solution de skeye ou la mienne marchent doivent marcher).
Faisant une qui remonte que les id=1 et une autre qui remonte que les id!=1 et n'existant pas dans les résultats de la 1ere tu iras plus vite


Message édité par anapajari le 27-02-2006 à 14:11:30
n°1314343
Beegee
Posté le 27-02-2006 à 14:24:21  profilanswer
 

Code :
  1. CREATE TABLE bugs
  2. (NAME VARCHAR2(10),
  3. ID NUMBER(9));
  4. INSERT INTO bugs VALUES ('bug 1', 1);
  5. INSERT INTO bugs VALUES ('bug 1', 1);
  6. INSERT INTO bugs VALUES ('bug 2', 3);
  7. INSERT INTO bugs VALUES ('bug 3', 1);
  8. INSERT INTO bugs VALUES ('bug 4', 1);
  9. SELECT NAME, SUM(CASE WHEN ID = 1 THEN 1 ELSE 0 END) AS CompteDeId
  10. FROM bugs
  11. GROUP BY NAME;


 
Résultat :
 
NAME,COMPTEDEID
bug 1,2
bug 2,0
bug 3,1
bug 4,1
 
(testé sous Oracle, mais il me semble que la syntaxe de SQL Server pour le CASE est la même)

n°1314348
isa21493
Posté le 27-02-2006 à 14:25:43  profilanswer
 

et ce serait pas possible de mettre ça:
 

Code :
  1. SELECT table_custom_field_string_table_0.value AS 'Area',
  2. IIF(Count(table_custom_field_string_table_0.bug_id),Count(table_custom_field_string_table_0.bug_id) AS 'Current',0)
  3. FROM ....


 
le problème c'est qu'il ne connait pas IIF
mais peut être qu'il existe autre chose de ce style, non?

n°1314349
Beegee
Posté le 27-02-2006 à 14:26:18  profilanswer
 

Cf ma réponse au-dessus.

n°1314355
isa21493
Posté le 27-02-2006 à 14:29:39  profilanswer
 

Code :
  1. SELECT table_custom_field_string_table_0.value AS 'Area',
  2. Count(CASE WHEN table_custom_field_string_table_0.bug_id)>0
  3. THEN table_custom_field_string_table_0.bug_id) AS 'Current' ELSE 0 END)


 
j'ai mis ça mais ça me met une erreur "expression de la colonne incorrecte: Count(CASE WHEN mantis_custom_field_string_table_0.bug_id)>0 "
 

n°1314360
skeye
Posté le 27-02-2006 à 14:31:03  profilanswer
 

(ce genre de sport c'est très spécifique au SGBD utilisé, en général...:/)


---------------
Can't buy what I want because it's free -
n°1314378
anapajari
s/travail/glanding on hfr/gs;
Posté le 27-02-2006 à 14:49:24  profilanswer
 

question mais mantis ça tourne sur mysql et pas mssql non?
 
Par ailleurs tu t'es trompé(e) dans la recopie de la requete de beegee:

Code :
  1. SELECT table_custom_field_string_table_0.value AS 'Area',
  2.      Count(CASE WHEN table_custom_field_string_table_0.bug_id = 1 THEN 1 ELSE 0) AS 'Current'


Message édité par anapajari le 27-02-2006 à 14:49:59
n°1314388
isa21493
Posté le 27-02-2006 à 14:59:38  profilanswer
 

ça ne marche quand meme pas.
 
j'ai essayé la solution avec UNION
 
ça marche sauf que ça me met 2 fois les name si elles sont dans l'une et l'autre
 

Code :
  1. SELECT table_custom_field_string_table_0.value , Count(table_custom_field_string_table_0.bug_id) AS 'Current'
  2. FROM base.table_bug_table table_bug_table_0, base.table_custom_field_string_table
  3. table_custom_field_string_table_0
  4. WHERE ....
  5. GROUP BY table_custom_field_string_table_0.value
  6. UNION
  7. SELECT table_custom_field_string_table_0.value , 0 AS 'Current'
  8. FROM base.table_bug_table table_bug_table_0, base.table_custom_field_string_table
  9. table_custom_field_string_table_0
  10. WHERE (table_custom_field_string_table_0.field_id=1)
  11. GROUP BY table_custom_field_string_table_0.value


 
comment dois je faire pour enlever les doublons?

n°1314394
isa21493
Posté le 27-02-2006 à 15:03:23  profilanswer
 

et comment faire pour que le résultat soit par ordre alphabétique?
car là j'ai d'abord par exemple  
 
bug1
bug3
bug4
bug2

n°1314400
Beegee
Posté le 27-02-2006 à 15:09:18  profilanswer
 

Essaye plutôt comme ça (y a quelques différences d'utilisation du mot clé CASE entre SQL Server et Oracle) :
 

Code :
  1. SELECT NAME,
  2.        SUM(test = CASE
  3.                     WHEN ID = 1 THEN 1
  4.                     ELSE 0
  5.                   END) AS CompteDeId
  6. FROM bugs
  7. GROUP BY NAME
  8. ORDER BY NAME;


 
plus d'infos ici si ça ne marche pas :
 
http://msdn.microsoft.com/library/ [...] o_5t9v.asp


Message édité par Beegee le 27-02-2006 à 15:09:38
n°1314403
anapajari
s/travail/glanding on hfr/gs;
Posté le 27-02-2006 à 15:12:43  profilanswer
 

isa21493 a écrit :


j'ai essayé la solution avec UNION
ça marche sauf que ça me met 2 fois les name si elles sont dans l'une et l'autre
comment dois je faire pour enlever les doublons?


anapajari a écrit :

Oui mais :D
si tu un "name" présent pour id=1 et id!=1 tu te retrouves dans les résultats avec deux fois ce "name" une fois à X et une fois à 0...
Ou alors faut faire péter un not exist  dans la 2eme requete!


Comme je te le disais il faut rajouter un not exist dans la 2eme requete
 
 

isa21493 a écrit :

et comment faire pour que le résultat soit par ordre alphabétique?
car là j'ai d'abord par exemple  
 
bug1
bug3
bug4
bug2


Lire la doc ça aide souvent, et ce quelque soit le SGBD. Regarde du coté de l'instruction ORDER.
 
 
Par ailleurs, les trois solutions proposées fonctionnent (celle de beegee, skeye ou la mienne) a toi de les adapter à ta requête et pas a nous de faire le boulot à ta place!

n°1314404
isa21493
Posté le 27-02-2006 à 15:14:59  profilanswer
 

merci
ça ne marche pas, je vais regarder ça
 
pour l'ordre c bon j'ai trouvé mais qqun sait il comment enlever mon doublon avec ma formule en haut?

n°1314405
isa21493
Posté le 27-02-2006 à 15:15:51  profilanswer
 

oui mais le not exist je le met où? je suis pas douée je sais lol mais ce que j'ai essayé ne marche pas

n°1314422
isa21493
Posté le 27-02-2006 à 15:27:04  profilanswer
 

c bon j'ai trouvé
merci à tous pour votre aide.
bonne fin de journée

n°1314445
Beegee
Posté le 27-02-2006 à 15:40:46  profilanswer
 

Ce serait sympa de mettre la solution maintenant, si jamais quelqu'un tombe sur ce sujet et en a besoin ...

mood
Publicité
Posté le   profilanswer
 


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

  Problème de requete

 

Sujets relatifs
[hibernate] problème avec une reqûete en HQL qui utilise un 'map'probleme requete
Problème avec une requêteproblème requête client vers servlet
Probleme variable de session et requete sqlProblème requête SQL
probleme requete REGEXPProbleme de requete.
[résolu] Requete MySQL : problème d'affichage par catégorie[ACCESS] probleme cumul sur requete
Plus de sujets relatifs à : Problème de requete


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