requete imbriqué complexe

requete imbriqué complexe - SQL/NoSQL - Programmation

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 :

Code :
  1. SELECT  DAYNAME(str_to_date(datevisite, '%d/%m/%y %T')) as jojo,m.designation,count(*),(select count(*) from ( SELECT distinct DAYNAME(str_to_date(datevisite, '%d/%m/%y %T')) as nomjour,
  2. str_to_date(datevisite, '%d/%m/%y')as ladate from identimotif idm,identification idf,motif m where
  3. idf.idclient=idm.idclient and m.idmotif= idm.idmotif and
  4. str_to_date(datevisite, '%d/%m/%y %T')  between
  5. 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
  6. group by nomjour) as go
  7. from identimotif idm,identification idf,motif m where
  8. idf.idclient=idm.idclient and m.idmotif= idm.idmotif and
  9. str_to_date(datevisite, '%d/%m/%y %T')  between
  10. 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')
  11. group by m.designation,jojo


 
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

Reply

Marsh Posté le 04-09-2012 à 02:04:30   

Reply

Marsh Posté le 04-09-2012 à 14:44:52    

SELECT  DAYNAME(str_to_date(datevisite, '%d/%m/%y %T')) as jojo,
        m.designation,
        count(*),
        (select count(*) from ( SELECT distinct DAYNAME(str_to_date(datevisite, '%d/%m/%y %T')) 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 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
         ) as go
 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 m.designation,
        jojo


 

Code :
  1. group by m.designation,
  2.         jojo


On met pas d'alias dans un group by
 
 

Code :
  1. group by m.designation,
  2.         DAYNAME(str_to_date(datevisite, '%d/%m/%y %T'))


 
 
Et on indente une requete :o
 
 


Message édité par KLeMiX le 04-09-2012 à 14:48:08

---------------
www.pronovolley.fr Faites vos prono sur la ligue de Volley et défiez vos amis. Des cadeaux en fin d'année  www.levoll.fr
Reply

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

Reply

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.

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed