PostgreSQL, getting min and max date from text column

前端 未结 1 717
鱼传尺愫
鱼传尺愫 2021-01-28 11:22

I have such situation in table:

1   01.02.2011
2   05.01.2011
3   06.03.2012
4   07.08.2011
5   04.03.2013
6   06.08.2011
7   
8   02.02.2013
9   04.06.2010
10           


        
相关标签:
1条回答
  • 2021-01-28 11:37

    Try something like:

    SELECT max(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')),
           min(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY'))
    FROM table_name;
    
    SELECT max(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')),
           min(to_date(nullif(mydatetxt,''), 'DD.MM.YYYY'))
    FROM table_name
    WHERE date_part('year',to_date(nullif(mydatetxt,''), 'DD.MM.YYYY')) = 2012;
    
    0 讨论(0)
提交回复
热议问题