Pages

[MySQL-5.5] Requete sql complexe pour calcul pourcentage sujet

vendredi 28 mars 2014




Bonjour les développeurs;
je suis actuellement en cours de développer une requête sql pour avoir un out put pourcentage. mes tables sont:
fait-vente:




























menage id-produitpénétration
12OUI
22OUI
31OUI
41OUI
...
...


le table produit:










































id-produitid-sous-categorienom-sous-categorieid-categorienom-categorie
118 portions1la vache qui rit
2216 portions1la vache qui rit
318 portions2RIKI
3216 portions2RIKI
418 portions3FROMY
5216 portions3FROMY



alors j'ai besoin de calculer le part de marché en terme de valeur de chaque categorie de produit (prix de sous categorie de produit*nbre de menage quit sont achetés) ma requête est comme suite :


Code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

select (0.200 * COUNT(`id-menage`)) AS `Somme Dépensé `, p.`nom-sous-categorie`, p.`nom-categorie`
from `fait-achat` f ,`produit` p
where p.`id-sous-categorie` =1 and p.`id-categorie`=1 and f.`id-produit`=p.`id-produit` and f.`penetration`="OUI"
group by p.`code-sou-cat`

UNION

select (1.620 * COUNT(`id-menage`)) AS `Somme Dépensé `, p.`nom-sous-categorie` , p.`nom-categorie`
from `fait-achat` f ,`produit` p
where p.`id-sous-categorie` =2 and p.`id-categorie`=1 and f.`id-produit`=p.`id-produit`and f.`penetration`="OUI"
group by p.`code-sou-cat`

union
select (220 * COUNT(`id-menage`)) AS `Somme Dépensé `, p.`nom-sous-categorie` , p.`nom-categorie`
from `fait-achat` f ,`produit` p
where p.`id-sous-categorie` =1 and p.`id-categorie`=2 and f.`id-produit`=p.`id-produit` and f.`penetration`="OUI"
group by p.`code-sou-cat`

UNION
select (2.420 * COUNT(`id-menage`)) AS `Somme Dépensé `, p.`nom-sous-categorie` , p.`nom-categorie`
from `fait-achat` f ,`produit` p
where p.`id-sous-categorie` =2 and p.`id-categorie`=2 and f.`id-produit`=p.`id-produit` and f.`penetration`="OUI"
group by p.`code-sou-cat`
.......



le résultat m'affiche comme valeur alors que je l'aime afficher en % càd:

Au lieu de :





























somme-depensécategorie-produitsous-categorie-produit
200.000RIKI8 portions
200.000RIKI16 portions
120.000FROMY8 portions
180.000FROMY16 portions
90.000LA VACHE QUI RIT8 portions
210.000LA VACHE QUI RIT16 portions



je veux













somme-depense-pourcentagecategorie-produit
40%RIKI
30%FROMY
30%LA VACHE QUI RIT


veuillez vous m'aider SVP :calim2:




Aucun commentaire:

Enregistrer un commentaire