sql >> Database teknologi >  >> RDS >> Mysql

Vælg alle datoer mellem to datoer, der ikke bruger en tabel (generer liste over datoer)

Her er forespørgslen:
Denne forespørgsel giver det rigtige resultat i begge databaser:MariaDB &MySQL .

SELECT ADDDATE('2012-02-10', INTERVAL @i:[email protected]+1 DAY) AS DAY
FROM (
SELECT a.a
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
JOIN (SELECT @i := -1) r1
WHERE 
@i < DATEDIFF('2012-02-15', '2012-02-10')



  1. Symfony2 - Doctrine2 QueryBuilder WHERE IN ManyToMany-feltet

  2. Sådan formateres tal med kommaer i MySQL

  3. Mysql-datofunktionen virker ikke for mindre end

  4. Indsættelse af SQL Server-data med Oracle® SQL*Loader