sql >> Base de Datos >  >> RDS >> Mysql

Cómo ordenar por CAMPO con GRUPO POR

Simplemente tiene un orden incorrecto para group by y order by;

...
ORDER BY
  FIELD( t.type, 'initial', 'commision', 'overpay', 'penalty', 'penalty2' )
GROUP BY
  t.type;

Debería ser:

...
GROUP BY
  t.type
ORDER BY
  FIELD( t.type, 'initial', 'commision', 'overpay', 'penalty', 'penalty2' );