简体   繁体   English

将列的数据类型从 STRING 格式更改为 DATE 格式

[英]Change data type of column from STRING format to DATE format

I am reading a file from ADLS location, in that one column Period_Ending_Date is having data type as STRING.我正在从 ADLS 位置读取一个文件,在该列Period_Ending_Date的数据类型为 STRING。 The Period_Ending_Date is having many dates in random order, I need to apply filter to get the latest date. Period_Ending_Date 有许多随机顺序的日期,我需要应用过滤器来获取最新日期。

I'm trying this code:我正在尝试这段代码:

select * from final_table WHERE Period_Ending_Date = (SELECT MAX(Period_Ending_Date) FROM final_table) select * 来自 final_table WHERE Period_Ending_Date = (SELECT MAX(Period_Ending_Date) FROM final_table)

But the problem is I'm getting the day with maximum, not the latest date.但问题是我得到的是最大日期,而不是最晚日期。 I can understand this is happening because of STRING data type.我可以理解这是因为 STRING 数据类型而发生的。 Please guide me how I can change this column to DATE data type or any other alternative to get the solution of this.请指导我如何将此列更改为 DATE 数据类型或任何其他替代方法以获得此问题的解决方案。

I'm working with Scala and SQL on Azure Databricks.我在 Azure Databricks 上使用 Scala 和 SQL。

what about changing SELECT MAX(Period_Ending_Date) FROM final_table to SELECT MAX(cast(Period_Ending_Date as date)) FROM final_table - performing explicit casting to date if date format is ISO8601 (YYYY-MM-DD) or using the to_date function ( doc ) to convert non-standard dates.如何将SELECT MAX(Period_Ending_Date) FROM final_tableSELECT MAX(cast(Period_Ending_Date as date)) FROM final_table - 如果日期格式为 ISO8601 (YYYY-MM-DD) 或使用to_date function ( doc ) 则执行显式转换为日期转换非标准日期。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM