Probléme sur une requête SQL
Bonjour,
je vous montre une première requête SQL de laquelle je dois m'inspirer :
Code:
1 2 3 4 5 6
| select count(distinct(a.clientid||a.productid)), d.label
from bopro.pjspviwf a, bopro.pjspvi_pjsplace b, bopro.pjsplace c, activities d
where a.state <> 1 and b.clientid = a.clientid and b.id = a.productid and
c.clientid = b.clientid and c.id = b.placeid and d.id = c.section
group by d.label
order by count(distinct(a.clientid||a.productid)) desc, d.label asc |
les conditions ne sont pas vraiment importantes, mais cette requête me fournit pour chaque label ( secteur d'activité ) le nombre de sites web.
Maintenant on me demande de faire une requête similaire mais de faire la différence parmi le nombre de site web de type A et de type B.
Pour avoir le type je peux le recuperer grâce à ceci :
e.lowcost ( soit a 1 ou a 0) de la table pjspvi e
Donc je voudrais obtenir un tableau ressemblant à ca :
Secteur nb type a nb type b
resto 25 30
fleuriste 10 12
J'ai beau avoir cherché plein de solution je n'ai pas trouvé la fonction ou la synthaxe exact pour arrivé a ce que je voulais. Le seul truc qui se rapproche le plus c'est ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| select count(distinct(a.clientid||a.productid)) AS "PVI", (select count(distinct(f.clientid||f.productid ))
from bopro.pjspviwf f, bopro.pjspvi_pjsplace g, bopro.pjsplace h, activities i, pjspvi j
where f.state <> 1 and g.clientid = f.clientid and g.id = f.productid and
h.clientid = g.clientid and h.id = g.placeid and i.id = h.section and f.clientid=j.clientid and j.lowcost=0
),d.label
from bopro.pjspviwf a, bopro.pjspvi_pjsplace b, bopro.pjsplace c, activities d, pjspvi e
where a.state <> 1 and b.clientid = a.clientid and b.id = a.productid and
c.clientid = b.clientid and c.id = b.placeid and d.id = c.section and a.clientid=e.clientid and e.lowcost=1
group by d.label
order by count(distinct(a.clientid||a.productid)) desc, d.label asc |
Mais le souci c'est que ça marche pour le premier type, mais pour le 2ème type il m'affiche la somme de tous les sites type B tous secteurs confondus sur chaque secteur. Qu'est-ce que j'ai pu oublier de mettre pour qu'il me trie bien le 2ème.
Merci d'avance.