简体   繁体   English

从具有值 DD-MMM-YY 格式存储为字符串的列中查找最小日期

[英]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

More about here更多关于这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 varchar和dd-mmm-yy格式的日期 - Date in varchar and dd-mmm-yy format 在redshift中将Date转换为DD-MMM-YY - convert Date to DD-MMM-YY in redshift SQL查询什么以获取今天更新的所有元组(CollectionDate列中提供的日期为DD-MMM-YY格式)? - SQL what is the query to get all tuples that are updated today (date provided in CollectionDate column in format DD-MMM-YY)? 如何在SQL Server中获取日期格式(dd-MMM-yy HH:mm:ss)? - How to get date format (dd-MMM-yy HH:mm:ss) in SQL Server? 如何将 dd-mmm-yy hh.mm nvarchar 转换为任何日期格式 - How to convert dd-mmm-yy hh.mm nvarchar to any date format 对于下面的 sqlplus 查询脚本,如何以 DD-MMM-YY HH.MM.SS 格式获取一列“evt_eventdate”的日期和时间 - for the below sqlplus query script, how to get DATE & TIME in DD-MMM-YY HH.MM.SS format for one column "evt_eventdate," only 如何在SQL Server R2中将日期时间格式化为dd-MMM-yy(或dd-mon-yy)? - How can I format a datetime in SQL Server R2 to dd-MMM-yy (or dd-mon-yy)? Oracle PL / SQL:SYSDATE与'DD-MMM-YY'的区别? - Oracle PL/SQL: how the SYSDATE is different from 'DD-MMM-YY'? 如何使用格式MMM / DD / YY或MMM / DD / YYYY验证日期字段? - How to validate date field with format MMM/DD/YY or MMM/DD/YYYY? Spark SQL-将日期从MMM dd,yyyy转换为yy-MMM-dd - spark sql - converting date from MMM dd, yyyy to yy-MMM-dd
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM