select*from ->(selectadddate ('1970-01- 01',t4*10000+t3*1000+t2*100+t1*10+t0)gen_datefrom ->(select0t0unionselect1unionsel"/> select*from ->(selectadddate ('1970-01- 01',t4*10000+t3*1000+t2*100+t1*10+t0)gen_datefrom ->(select0t0unionselect1unionsel">

 >  기사  >  데이터 베이스  >  MySQL의 날짜 범위에서 일을 생성하는 방법은 무엇입니까?

MySQL의 날짜 범위에서 일을 생성하는 방법은 무엇입니까?

王林
王林앞으로
2023-09-22 15:49:02804검색

如何从 MySQL 中的日期范围生成天数?

adddate() 함수를 사용하여 다음 쿼리를 사용하면 "2016-12-15"와 "2016-12-31" 사이의 일 수를 생성할 수 있습니다. -

mysql> select * from
    -> (select adddate('1970-01-01',t4*10000 + t3*1000 + t2*100 + t1*10 + t0) gen_date from
    -> (select 0 t0 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
    -> (select 0 t1 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
    -> (select 0 t2 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
    -> (select 0 t3 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
    -> (select 0 t4 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
    -> Where gen_date between '2016-12-15' and '2016-12-31'
    -> ;
+------------+
| gen_date   |
+------------+
| 2016-12-15 |
| 2016-12-16 |
| 2016-12-17 |
| 2016-12-18 |
| 2016-12-19 |
| 2016-12-20 |
| 2016-12-21 |
| 2016-12-22 |
| 2016-12-23 |
| 2016-12-24 |
| 2016-12-25 |
| 2016-12-26 |
| 2016-12-27 |
| 2016-12-28 |
| 2016-12-29 |
| 2016-12-30 |
| 2016-12-31 |
+------------+
17 rows in set (0.30 sec)

위 내용은 MySQL의 날짜 범위에서 일을 생성하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제