简体   繁体   中英

How to join tables by date column with different date format in SQL Vertica?

I have two tables in SQL

table1:

date        col2
2020-10-25  2
2020-10-20  20

table2:

date        col1
25.10.2020  1
20.10.2020  10

As you can see i have different format of date. My question is how can I in Vertica SQL join this two tables on date column in each table?

Simply I need to join this two tables by date column co for examplle I need table with 3 columns: date, col1, col2 like below:

result:

date        col1  col2
2020-10-25  1     2
2020-10-20  10    20

You have a real problem with your data model. date s should be stored using the appropriate date/time type, not as strings .

You can convert to a date for the join , using:

select to_date(t1.date, 'YYYY-MM-DD'), t1.col1, t2.col2
from table1 t1 join
     table2 t2
     on to_date(t1.date, 'YYYY-MM-DD') = to_date(t2.date, 'DD.MM.YYYY')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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