vendredi 10 janvier 2020

How do I use select alias inside GROUP_CONCAT?

  1. I am averaging 4 columns and giving an alias score.
  2. Now, I am trying to use score alias inside GROUP_CONCAT to get rank.
  3. Everything works except when I add (SELECT GROUP_CONCAT( score ORDER BY score DESC) FROM math )) AS rank.
  4. I understand it does not work because score does not exist in the math table. But what do I need to do to make it work?

Here is my query in laravel 5.5 -

$ranking = DB::select('SELECT *, (a.addition_accuracy + a.subtraction_accuracy + a.multiplication_accuracy + a.division_accuracy)/4 as score, (SELECT GROUP_CONCAT( score ORDER BY score DESC) FROM math )) AS rank FROM math a where level = 5');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire