sql >> Databasteknik >  >> RDS >> Mysql

MySQL - Hur visar man alla dagars poster i en viss månad?

Om du känner till ditt inmatningsår och månad kan du alltid ställa in den första dagen, säg att inmatningen är Y = 2012 M=02 , den första dagen skulle alltid vara 2012-02-01 och med det datumet kan du få den sista dagen och sedan datumen inom det intervallet. Något som

select a.Date 
from (
    select last_day('2012-02-01') - 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 
where a.Date between '2012-02-01' and last_day('2012-02-01') order by a.Date;

+------------+
| Date       |
+------------+
| 2012-02-01 |
| 2012-02-02 |
| 2012-02-03 |
| 2012-02-04 |
| 2012-02-05 |
| 2012-02-06 |
| 2012-02-07 |
| 2012-02-08 |
| 2012-02-09 |
| 2012-02-10 |
| 2012-02-11 |
| 2012-02-12 |
| 2012-02-13 |
| 2012-02-14 |
| 2012-02-15 |
| 2012-02-16 |
| 2012-02-17 |
| 2012-02-18 |
| 2012-02-19 |
| 2012-02-20 |
| 2012-02-21 |
| 2012-02-22 |
| 2012-02-23 |
| 2012-02-24 |
| 2012-02-25 |
| 2012-02-26 |
| 2012-02-27 |
| 2012-02-28 |
| 2012-02-29 |
+------------+
29 rows in set (0.00 sec)


  1. Hur kan jag undkomma ingången till en MySQL-db i Python3?

  2. hur man ställer in automatisk inkrementkolumn med sql-utvecklare

  3. Hur TRIM_ORACLE() fungerar i MariaDB

  4. Hur infogar man en enorm Panda-dataram i MySQL-tabellen med Parallell Insert Statement?