sql - Comparing between two dates in Oracle DB is not giving proper result
问题描述
I've got two DATE
columns in my table having below values:
Order_date Service_date
01-06-17 31-01-18
01-06-17 01-10-18
01-06-17 01-07-18
01-06-17 01-04-18`
When I run the below query:
SELECT
TRUNC(Order_date) Order_date,
TRUNC(Service_date) Service_date,
CASE
WHEN trunc(Order_date) > trunc(Service_date) THEN 'Y'
ELSE 'N'
END actual
FROM
table_x;
I get the result as:
Order_date Service_date actual
01-06-17 31-01-18 Y
The expected answer should be 'N'.
But if I run a similar query, by actually passing the DATE
values, it gives me proper result.
SELECT
to_date('01-06-17','DD-MM-RR') Order_date,
to_date('31-01-18', 'DD-MM-RR') Service_date,
CASE
WHEN to_date('01-06-17','DD-MM-RR') > to_date('31-01-18', 'DD-MM-RR') THEN 'Y'
ELSE 'N'
END actual
FROM
table_x;
Order_date Service_date actual
01-06-17 31-01-18 N
Why isn't it giving the the expected result with the original query?
解决方案
推荐阅读
- ckeditor - 无界的 CkEditor5 视图值
- python - 如何使用“onehot_enc”实现朴素贝叶斯算法?
- symfony - Nginx symfony““try_files”指令中的参数数量无效”
- javascript - 当存在具有特定名称的键时,将对象推入数组中
- android - 添加依赖项 CardView 和 RecylerView 时出现 Gradle 错误
- java - Java 转换器空元素
- angular6 - Splice 返回已删除的元素,而不是返回所有其他未删除的元素
- ibm-cloud - IBM Watson Assistant:聊天机器人实体区别
- kotlin - 如何使用集合运算符在 Kotlin 中按日期删除对象列表中的重复项?
- python - 尝试并排除循环用户输入的覆盖