在Hive中查找最大日期

e7arh2l6  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(302)

我有一个名为“date”的列,它是string数据类型。01-24-2018 04-30-2017
如何找到字符串中这些日期的最大值?
我使用的查询没有返回预期的最大值。

max(to_date(from_unixtime(unix_timestamp(b.Date,'MM-dd-yyyy')))
acruukt9

acruukt91#

尝试

MAX( cast(to_date(from_unixtime(unix_timestamp(yourdate , 'MM-dd-yyyy'))) as date))

编辑:在您的评论中,您提到您需要获取最长日期的帐户详细信息。您可以使用此选项。

SELECT a.id,
       b.contract,
       CAST (
          TO_DATE (
             from_unixtime (unix_timestam‌​p (b.date, 'MM-dd-yyyy'))) AS DATE)
          AS MAX_DATE
  FROM acct a JOIN customer b ON (b.partyid = a.offerid)
 WHERE CAST (
          TO_DATE (
             from_unixtime (unix_timestam‌​p (b.date, 'MM-dd-yyyy'))) AS DATE) IN 

  ( SELECT 
         MAX (
            CAST (
               TO_DATE (
                  from_unixtime (unix_timestam‌​p (b.date, 'MM-dd-yyyy'))) AS DATE))
    FROM acct a JOIN customer b ON (b.partyid = a.offerid)
   WHERE b.contract = 200427747 );

相关问题