Compter jusqu’à 100 avec MySQL

Il est parfois utile de compter simplement pour ensuite faire une jointure sur cette liste.

Pour MySQL, il faut utiliser une méthode un peu brute et sans table temporaire.

select Unites.Nombre + (Dizaines.Nombre-1)*10 as Nombre
 from ( 
 Select 1 as Nombre Union All Select 2 Union All Select 3 Union All Select 4 Union All Select 5 Union All Select 6 Union All Select 7 Union All Select 8 Union All Select 9 Union All Select 10
 ) As Unites
 inner join (
 Select 1 as Nombre Union All Select 2 Union All Select 3 Union All Select 4 Union All Select 5 Union All Select 6 Union All Select 7 Union All Select 8 Union All Select 9 Union All Select 10
 ) As Dizaines on 1=1

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée.