[英]Join tables on dates, with dirty date field
在 AWS Athena 中,我嘗試使用日期連接數據庫中的兩個表,但其中一個表 (table2) 不干凈,並且包含不是日期的值,如下所示。
| table2.date |
| ---- |
|6/02/2021|
|9/02/2021|
|1431 BEL & 1628 BEL."|
|15/02/2021|
|and failed to ....|
|18/02/2021|
|19/02/2021|
我無法對清理這張桌子產生任何影響。
我目前的查詢是:
SELECT *
FROM table1
LEFT JOIN table2
ON table1.operation_date = cast(date_parse(table2."date",'%d/%m/%Y') as date)
LIMIT 10;
我試過使用regex_like(col, '[az]')
,但這仍然留下數字值,但不是日期。
如何讓查詢忽略不是日期的值?
您可以使用try
函數包裝轉換表達式,如果轉換失敗,它將解析為NULL
。
select
try(date_parse(col, '%d/%m/%Y'))
from(values
('6/02/2021'),
('9/02/2021'),
('1431 BEL & 1628 BEL.'),
('15/02/2021'),
('and failed to ....'),
('18/02/2021'),
('19/02/2021')
) as t(col)
# | _col0 |
---|---|
1 | 2021-02-06 00:00:00.000 |
2 | 2021-02-09 00:00:00.000 |
3 | |
4 | 2021-02-15 00:00:00.000 |
5 | |
6 | 2021-02-18 00:00:00.000 |
7 | 2021-02-19 00:00:00.000 |
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.