使用场景:进行某一日期范围内的数据查询
查询结果:空,查询不到符合条件的数据。
Sql展示:
SELECT
a.dt_plan AS planDate,
a.sd_status AS planStatus
FROM
c_hpl_plan a
WHERE
a.id_phr = '6576727112f1a21849639530'
-- 第一种写法
and a.dt_plan >= DATE_FORMAT('2023-12-01 00:00:00','yyyy-mm-dd HH24:mi:ss')
and a.dt_plan <= DATE_FORMAT('2023-12-16 00:00:00','yyyy-mm-dd HH24:mi:ss')
-- 第二种写法
and a.dt_plan BETWEEN DATE_FORMAT('2023-12-01 00:00:00','yyyy-mm-dd HH24:mi:ss') and DATE_FORMAT('2023-12-16 00:00:00','yyyy-mm-dd HH24:mi:ss');
-- 修改方案:
SELECT
a.dt_plan AS planDate,
a.sd_status AS planStatus
FROM
c_hpl_plan a
WHERE
a.id_phr = '6576727112f1a21849639530'
AND a.dt_plan <= '2023-12-16 00:00:00'
AND a.dt_plan >= '2023-02-01 00:00:00';
数据结果: