Scores : SOS AIDE

greg6fr Messages postés 28 Date d'inscription mercredi 20 août 2008 Statut Membre Dernière intervention 23 janvier 2014 - 12 avril 2009 à 21:01
EricSQL Messages postés 33 Date d'inscription samedi 11 octobre 2008 Statut Membre Dernière intervention 24 février 2011 - 21 juin 2009 à 13:24
bonjour a tous.
je suis un debutant et voila qu'on me confie un preojet en sql/oracle, ou je ne sais par ou debuter les amis.
pouvez vous m'aider.
VOICI L'EXERCICE
Un petit QCM est basée sur 2 tables.L'une de ces tables contient les informatons sur les sondés(nom,prenom,etc.) ainsi que leurs reponses au questions(tables T_PANEL_PNL).
L'autre table contient, elle les reponses aux questions(T_REPONSES_RPS).
-----------------------------------------------------------------------------------------------------------
TACHE:                                                                                                                                                  -
Il vous est demandé d'obtenir, à lo'aide d'une requete, le nombre de bonne reponses de chaque sondés.    -
VOICI LE JEU D'ESSAI UTILISE:                                                                                                        -
-----------------------------------------------------------------------------------------------------------

/** CREATION DE LA TABLE NOMMEE T_PANEL_PNL CONTENANT LE NOM DU SONDE ET LES REPONSES CHOISIES
**/

CREATE TABLE T_PANEL_PNL(
PNL_NOM VARCHAR(16),
PNL_REPONSE1 INTEGER,
PNL_REPONSE2 INTEGER,
PNL_REPONSE3 INTEGER,
PNL_REPONSE4 INTEGER,
PNL_REPONSE5 INTEGER);

/** INSERTION DANS LA TABLE T_PANEL_PNL
**/

INSERT INTO T_PANEL_PNL VALUES ('Pierre',1,2,3,0,0);
INSERT INTO T_PANEL_PNL VALUES ('Paul',1,5,3,2,1);
INSERT INTO T_PANEL_PNL VALUES ('Jacques',0,3,3,2,2);

/** CREATION DE LA TABLE NOMMEE T_REPONSES_RPS CONTENANT LES REPONSES
**/

CREATE TABLE T_REPONSES_RPS(
RPS_REPONSE1 INTEGER,
RPS_REPONSE2 INTEGER,
RPS_REPONSE3 INTEGER,
RPS_REPONSE4 INTEGER,
RPS_REPONSE5 INTEGER);

/** INSERTION DANS LA TABLE T_REPONSES_RPS
**/

INSERT INTO T_REPONSES_RPS VALUES (1,4,3,2,1);

La reponse attendue est la suivante:

PNL_NOM BONNES_REPONSES
---------------------------------------------
Paul 4
Pierre 2
Jacques 2

2 réponses

aieeeuuuuu Messages postés 698 Date d'inscription jeudi 16 janvier 2003 Statut Membre Dernière intervention 20 mai 2011 3
14 avril 2009 à 11:29
Bonjour,

La modélisation n'est pas top pour ce genre de chose (il eut fallu un table a part pour les réponses des candidats), mais si tu n'a pas moyen de modifier la strucuture de la base, tu peux faire ca :

SELECT Nom, Count(*)
FROM T_PANEL_PNL P
INNER JOIN T_REPONSES_RPS R1 ON (P.PNL_REPONSE1  =R1.RPS_REPONSE1)
INNER JOIN T_REPONSES_RPS R1 ON (P.PNL_REPONSE2  =R1.RPS_REPONSE2)
INNER JOIN T_REPONSES_RPS R1 ON (P.PNL_REPONSE3  =R1.RPS_REPONSE3)
INNER JOIN T_REPONSES_RPS R1 ON (P.PNL_REPONSE4  =R1.RPS_REPONSE4)
INNER JOIN T_REPONSES_RPS R1 ON (P.PNL_REPONSE5  =R1.RPS_REPONSE5)
UNION
SELECT Nom, 0
FROM T_PANEL_PNL P,
T_REPONSES_RPS R
WHERE P.REPONSE1 <> R.RPS_REPONSE1
AND P.REPONSE2 <> R.RPS_REPONSE2
AND P.REPONSE3 <> R.RPS_REPONSE3
AND P.REPONSE4 <> R.RPS_REPONSE4
AND P.REPONSE5 <> R.RPS_REPONSE5

C'est un peu lourd, mais vue la structure de la base, je ne vois pas comment faire une requete plus "classe"
0
EricSQL Messages postés 33 Date d'inscription samedi 11 octobre 2008 Statut Membre Dernière intervention 24 février 2011
21 juin 2009 à 13:24
Bonjour,

comme ceci ce sera plus propre :

Select res.pnl_nom
, case PNL_REPONSE1 when RPS_REPONSE1 then 1 else 0 end
+ case PNL_REPONSE2 when RPS_REPONSE2 then 1 else 0 end
+ case PNL_REPONSE3 when RPS_REPONSE3 then 1 else 0 end
+ case PNL_REPONSE4 when RPS_REPONSE4 then 1 else 0 end
+ case PNL_REPONSE5 when RPS_REPONSE5 then 1 else 0 end
from T_PANEL_PNL res
, T_REPONSES_RPS rep
;

/Eric
0
Rejoignez-nous