我在下面运行了这两个脚本,它们给出了两个不同的结果。第一个没有包括4月30日的数据,但后者确实如此。我正在使用oracle sql。有人可以协助吗?
select distinct * from a where (m_date between'01-MAY-17' AND '30-MAY-17');
select distinct * from a where m_date like '%-MAY-17';
我使用了to_date函数,它工作正常:
从'01-MAY-17'和'30 -MAY-17'之间的to_date(m_date)中选择distinct *
这产生了与like子句相同的结果:
从像'%-MAY-17'这样的m_date中选择distinct *
你的条款
select distinct * from a where to_date (m_date) between'01-MAY-17' AND '30-MAY-17'
与说(伪代码)相同
...where to_date (m_date) between '01-may-17 00:00:00' AND '30-may-17 00:00:00'...
在早上12点以外有任何时间元素的5/30排除和日期值。 (另外,5月确实有31天)。
假设m_date是日期数据类型并假设您想要在may的月份中的所有值,那么执行以下操作将更为正确。
... where m_date >= to_date('01-may-17') and m_date < to_date('01-jun-17')...