requete imbriqué complexe - SQL/NoSQL - Programmation
Marsh Posté le 04-09-2012 à 14:44:52
SELECT DAYNAME(str_to_date(datevisite, '%d/%m/%y %T')) as jojo, |
Code :
|
On met pas d'alias dans un group by
Code :
|
Et on indente une requete
Marsh Posté le 05-09-2012 à 01:14:51
bonjour j'ai réussi à la réaliser avec case when :
select DAYNAME(str_to_date(datevisite, '%d/%m/%y')) as jour,m.designation ,
case DAYNAME(str_to_date(datevisite, '%d/%m/%y')) when 'Monday' then count(*)/(select count(*) from ( SELECT distinct DAYNAME(str_to_date(datevisite, '%d/%m/%y')) as nomjour,
str_to_date(datevisite, '%d/%m/%y')as ladate from identimotif idm,identification idf,motif m where
idf.idclient=idm.idclient and m.idmotif= idm.idmotif and DAYNAME(str_to_date(datevisite, '%d/%m/%y'))='Monday' and
str_to_date(datevisite, '%d/%m/%y %T') between
str_to_date('20/03/12 08:30:00', '%d/%m/%y %T') and str_to_date('06/07/12 16:30:00', '%d/%m/%y %T')) as res
group by nomjour) when 'Friday' then count(*)/(select count(*) from ( SELECT distinct DAYNAME(str_to_date(datevisite, '%d/%m/%y')) as nomjour,
str_to_date(datevisite, '%d/%m/%y')as ladate from identimotif idm,identification idf,motif m where
idf.idclient=idm.idclient and m.idmotif= idm.idmotif and DAYNAME(str_to_date(datevisite, '%d/%m/%y'))='Friday' and
str_to_date(datevisite, '%d/%m/%y %T') between
str_to_date('20/03/12 08:30:00', '%d/%m/%y %T') and str_to_date('06/07/12 16:30:00', '%d/%m/%y %T')) as res
group by nomjour)
when 'Tuesday' then count(*)/(select count(*) from ( SELECT distinct DAYNAME(str_to_date(datevisite, '%d/%m/%y')) as nomjour,
str_to_date(datevisite, '%d/%m/%y')as ladate from identimotif idm,identification idf,motif m where
idf.idclient=idm.idclient and m.idmotif= idm.idmotif and DAYNAME(str_to_date(datevisite, '%d/%m/%y'))='Tuesday' and
str_to_date(datevisite, '%d/%m/%y %T') between
str_to_date('20/03/12 08:30:00', '%d/%m/%y %T') and str_to_date('06/07/12 16:30:00', '%d/%m/%y %T')) as res
group by nomjour) when 'Wednesday' then count(*)/(select count(*) from ( SELECT distinct DAYNAME(str_to_date(datevisite, '%d/%m/%y')) as nomjour,
str_to_date(datevisite, '%d/%m/%y')as ladate from identimotif idm,identification idf,motif m where
idf.idclient=idm.idclient and m.idmotif= idm.idmotif and DAYNAME(str_to_date(datevisite, '%d/%m/%y'))='Wednesday' and
str_to_date(datevisite, '%d/%m/%y %T') between
str_to_date('20/03/12 08:30:00', '%d/%m/%y %T') and str_to_date('06/07/12 16:30:00', '%d/%m/%y %T')) as res
group by nomjour) when 'Thursday' then count(*)/(select count(*) from ( SELECT distinct DAYNAME(str_to_date(datevisite, '%d/%m/%y')) as nomjour,
str_to_date(datevisite, '%d/%m/%y')as ladate from identimotif idm,identification idf,motif m where
idf.idclient=idm.idclient and m.idmotif= idm.idmotif and DAYNAME(str_to_date(datevisite, '%d/%m/%y'))='Thursday' and
str_to_date(datevisite, '%d/%m/%y %T') between
str_to_date('20/03/12 08:30:00', '%d/%m/%y %T') and str_to_date('06/07/12 16:30:00', '%d/%m/%y %T')) as res
group by nomjour) end from identimotif idm,identification idf,motif m where
idf.idclient=idm.idclient and m.idmotif= idm.idmotif and
str_to_date(datevisite, '%d/%m/%y %T') between
str_to_date('20/03/12 08:30:00', '%d/%m/%y %T') and str_to_date('06/07/12 16:30:00', '%d/%m/%y %T')
group by DAYNAME(str_to_date(datevisite, '%d/%m/%y')),m.designation
Marsh Posté le 05-09-2012 à 07:59:59
lol
Faut revoir le formatage en premier si tu veux que quelqu'un t'aide.
Sinon a vue de nez il y a moyen de faire ca en beaucoup plus court et lisible en utilisant des JOIN et different group by.
Et surtout, eviter les subselect dans le case, ca va plomber les perfs d'une maniere extraordinaire.
Marsh Posté le 04-09-2012 à 02:04:30
bonjour je suis nouveau sur le forum et merci pour les gens qui vont me répondre
voila j'ai fais cette requête en mysql et elle me renvoi pas de résultat :
j'aimerai savoir si il ya une erreur dans la syntaxe (quand j’exécute chaque requête séparément ça marche )
merci d'avance