[英]How to join tables by date column with different date format in SQL Vertica?
我在 SQL 中有兩張表
表格1:
date col2
2020-10-25 2
2020-10-20 20
表2:
date col1
25.10.2020 1
20.10.2020 10
如您所見,我有不同的日期格式。 我的問題是如何在 Vertica SQL 中在每個表的日期列上加入這兩個表?
只需按日期列 co 連接這兩個表,例如,我需要具有 3 列的表:日期、col1、col2,如下所示:
結果:
date col1 col2
2020-10-25 1 2
2020-10-20 10 20
您的數據 model 確實存在問題。 date
應該使用適當的日期/時間類型存儲,而不是字符串。
您可以使用以下方法轉換為join
的日期:
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')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.