[英]Find min date from a column which has values DD-MMM-YY format stored as string
One of the column(file_date) in a table is of type string and has values of dates in DD-MMM-YY format.表中的列(file_date)之一是字符串类型,日期值采用 DD-MMM-YY 格式。 How do I find min(date) from the column.如何从列中找到最小(日期)。
I wrote simple query Select min(file_date) from tablename我从表名写了简单的查询 Select min(file_date)
It gives output as: 01-Dec-22它给出 output 作为:01-Dec-22
But there are dates from earlier months present in the table example 28-Aug-22,31-Oct-22,14-Nov-22但是表示例 28-Aug-22,31-Oct-22,14-Nov-22 中存在较早月份的日期
The expected output is 28-Aug-22 as this is the earliest date from which data is present in the table.预期的 output 是 22 年 8 月 28 日,因为这是表格中出现数据的最早日期。
Oracle : Oracle :
WITH -- sample data
tbl (ID, FILE_DATE) AS
(
Select 1, '01-Dec-22' From Dual Union All
Select 1, '21-Jan-22' From Dual Union All
Select 1, '01-Dec-21' From Dual Union All
Select 1, '01-Jan-23' From Dual Union All
Select 1, '10-Dec-20' From Dual Union All
Select 1, '11-Jan-23' From Dual
)
-- your SQL
Select Min(To_Date(FILE_DATE, 'dd-Mon-yy')) "MIN_DATE" From tbl;
MIN_DATE
---------
10-DEC-20
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.