sql >> Database >  >> RDS >> Mysql

MySQL geeft alle datums tussen bereik weer

U kunt het volgende gebruiken om uw lijst met datums te genereren:

select a.Date,  s.*
from 
(
  select curdate() + INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date
  from (select 0 as a union all select 1 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) as a
  cross join (select 0 as a union all select 1 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) as b
  cross join (select 0 as a union all select 1 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) as c
) a
inner join schedule s
  on a.Date >= s.fromDate 
  and a.Date <= s.toDate

Zie SQL Fiddle met demo



  1. Moet alle triggers in de SQL Server-database vermelden met tabelnaam en tabelschema

  2. MySQL:snelste manier om het aantal rijen te tellen

  3. javafx verbinding met mysql

  4. Hoe de omgevingsvariabele PYTHON_EGG_CACHE op Mac in te stellen?