Sort numbers and seasons correctly

0

Next I need to formulate a SELECT , whose function is to show in order of seasons the episodes, example T1E1 , T1E2 , T2E1 continuously for the following structure:

  'eid' int(10) NOT NULL,
  'aid' varchar(6) NOT NULL,
  'hits' int(11) NOT NULL,
  'titulo' varchar(200) DEFAULT NULL,
  'numero' varchar(15) DEFAULT NULL,
  'descargas' text,
  'videos' text NOT NULL,
  'estado' int(1) NOT NULL DEFAULT '0',
  'fecha_salida' date NOT NULL DEFAULT '0000-00-00',
  'temporada' varchar(15) DEFAULT NULL

is returning this way: link

    
asked by anonymous 11.02.2018 / 18:36

2 answers

0

The problem is that the numero and temporada columns have been declared as VARCHAR , so it is being sorted alphabetically. To correct this problem, declare it as INTEGER or ORDER BY together with CAST as follows:

SELECT *
  FROM 'lista_animes_capitulos'
 ORDER BY CAST('temporada' AS unsigned),
          CAST('numero' AS unsigned)

See working in SQL Fiddle .

    
11.02.2018 / 19:36
0
  

MySQL Documentation: ORDER BY Optimization

SELECT * FROM 'tabela' ORDER BY 'temporada', 'numero';

You can also change the order of each field with ASC (lowest to highest) and DESC (highest to lowest) as the documentation suggests.

    
11.02.2018 / 19:07