Problème de ORDER BY sur un champ de type case when

lundi 21 juillet 2014

Bonjour,




J'ai remarqué qu'il n'était pas possible de faire un "ORDER BY CASE WHEN mon_champ" lorsque "mon_champ" est le résultat d'un CASE WHEN.


Exemple :




SELECT
case when champ1 in ('toto', 'titi', 'tutu') then champ1 else 'tata' end as alias1,
champ2,
-- Champs agrégats (SUM, COUNT etc)
FROM tables
GROUP BY
case when champ1 in ('toto', 'titi', 'tutu') then champ1 else 'tata' end,
champ2
ORDER BY case alias1 when 'tutu' then 1 when 'titi' then 2 when 'tutu' then 3 else 4 end, champ2


Est-ce que c'est normal ?




Cordialement,





0 commentaires:

Enregistrer un commentaire

 

Lorem

Ipsum

Dolor