回答

收藏

如何获取MySQL中的两个日期之间的日期列表选择查询

技术问答 技术问答 97 人阅读 | 0 人回复 | 2023-09-13

这个问题已经在这里有了答案
$ }' {" h& U: {3 T5 @8 y2 J' ]获取两个日期之间的日期列表 (20个答案)$ l! ]% }  b3 U5 N
7年前关闭。' q  ?. w6 i5 q; M# p1 W
我想通过选择查询将日期列表放在两个日期之间。例如:
5 y3 ?, g8 Q: |* F% h. M如果我给出“ 2012-02-10”和“ 2012-02-15”,则需要结果。
7 z& D8 z( a& wdate      
) w1 H1 B2 ^3 ]7 P" ]" n9 N----------0 j% d; P" B. E6 G- _+ b2 \
2012-02-10
' v" s9 ^; `+ W- ^5 {+ J2012-02-11
7 A% f* a% O8 \! b  ~" b. ~6 ^9 @2012-02-125 F5 C( _. _9 S+ N7 B$ g
2012-02-132 O* T& J! K! [% u( K5 X: N  s' ?
2012-02-148 T9 ]2 d- I* _8 F9 t& u+ v( @
2012-02-15' ]% k$ W1 l+ ?( f& c: b
我怎样才能得到?3 i" k5 n, R, W" @( I2 A% u1 k$ Z2 T
               
# M) c, \5 B7 s2 j. O4 b  e! _解决方案:! B7 D- [6 z2 D. {) g
               
* ~7 W* H$ W1 R1 n+ V3 r( G' {  R
* t, x! k+ U3 r0 s& N
                尝试:0 G% k6 O3 x7 y8 _+ ~9 J, K! x
select * from ; r- F/ V3 _3 b  J- s
(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
% H* I8 w& f( R (select 0 i 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,8 C5 [3 Q$ K7 N2 A, g( m7 V
(select 0 i 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,* X( V) l+ V; i* K- I% |& Z
(select 0 i 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,; }3 ?6 R, }. F1 s
(select 0 i 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,8 S" i1 w. _0 g1 |8 ^8 ?. N8 d: g
(select 0 i 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
& u6 g+ _2 m2 {2 Vwhere selected_date between '2012-02-10' and '2012-02-15': q; {- e  U, d7 j
-日期范围可长达近300年。
2 g; h4 i+ k; \+ q7 E7 g- j5 H  D* Z[根据UrvishAtSynapse的建议编辑进行更正。]
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则