SQL : count(*) NULL

Résolu/Fermé
Stef60 Messages postés 251 Date d'inscription jeudi 31 mai 2007 Statut Membre Dernière intervention 22 avril 2009 - 5 déc. 2007 à 14:54
Stef60 Messages postés 251 Date d'inscription jeudi 31 mai 2007 Statut Membre Dernière intervention 22 avril 2009 - 5 déc. 2007 à 17:11
Bonjour,
j'ai un souci avec une requete SQL
voici la requete:
SELECT count(DISTINCT a.id), count(DISTINCT b.id) , count(DISTINCT c.id), count(DISTINCT d.id)
FROM
(SELECT id FROM table WHERE prj_id="18" AND status="10") a,
(SELECT id FROM table WHERE prj_id="18" AND status="15") b,
(SELECT id FROM table WHERE prj_id="18" AND status="20") c,
(SELECT id FROM table WHERE prj_id="18" AND status="40") d

Mon souci c'est que si une des requetes de la clause FROM (a->d) ne retourne aucune valeur
alors tous mes count sont egale a 0

Comment contourner ce probleme?

D'avance merci.
A voir également:

3 réponses

Stef60 Messages postés 251 Date d'inscription jeudi 31 mai 2007 Statut Membre Dernière intervention 22 avril 2009 41
5 déc. 2007 à 17:11
j'ai trouvé la solution.

SELECT a.cnt
, b.cnt
, c.cnt
, d.cnt
FROM ( SELECT COUNT(DISTINCT id) AS cnt
FROM matable
WHERE prj_id='18'
AND STATUS='10'
) AS a
, ( SELECT COUNT(DISTINCT id) AS cnt
FROM matable
WHERE prj_id='18'
AND STATUS='15'
) AS b
, ( SELECT COUNT(DISTINCT id) AS cnt
FROM matable
WHERE prj_id='18'
AND STATUS='20'
) AS c
, ( SELECT COUNT(DISTINCT id) AS cnt
FROM matable
WHERE prj_id='18'
AND STATUS='40'
) AS d
2
WinGs Messages postés 245 Date d'inscription lundi 23 avril 2007 Statut Membre Dernière intervention 25 novembre 2008 34
5 déc. 2007 à 15:01
essaye en rajoutant IS NOT NULL dans tes SELECT a->d
0
Stef60 Messages postés 251 Date d'inscription jeudi 31 mai 2007 Statut Membre Dernière intervention 22 avril 2009 41
5 déc. 2007 à 15:13
J'ai essayé avec ca:
....
(SELECT id IS NOT NULL FROM table WHERE prj_id="18" AND status="10") a,
....

et ca me repond "Unknown column 'a.id' in 'field list'"
0