【问题标题】:Trying to use regex_replace to extract numbers尝试使用 regex_replace 提取数字
【发布时间】:2019-08-06 21:39:10
【问题描述】:

我有一个包含 dma 代码的专栏。它们有以下两种格式:

a) 100123

b)="100123"

我正在尝试以 a) 格式获取它们。

我尝试过使用 NULLIF(regexp_replace(column_name, '\D','','g'), '')::numeric

但我无法使用正确的语法。

选择 ds.from_date ,state_map.state_name 作为状态 ,dma_region_name ,zip_map.dma_name 作为 dma_name ,regexp_replace(dma_region_id,'','[0-9]') ,邮政编码名称 ,search_codes_map.is_sourcecode ,search_codes_map.geo ,search_codes_map.tactic ,search_codes_map.engine ,search_codes_map.strategy ,search_codes_map.device ,search_codes_map.campaign_type ,search_codes_map.keyword_type ,search_codes_map.intent_bucket ,search_codes_map.match_type ,search_codes_map.test_indicator ,SUM(ds.clicks) AS 点击次数 ,SUM(ds.impr) AS 展示次数 ,SUM(ds.cost) 作为成本 ,SUM(ds.phone_calls) AS phone_calls ,SUM(ds.dialogtech_calls) AS dialogtech_calls ,SUM(ds.ebrc_completion) 作为 ebrc_completion ,0 作为 smart_phone_leads ,0 作为 smart_web_leads ,0 作为 smart_leads ,0 作为 smart_agent_appointments ,0 作为 smart_oles ,0 作为 phone_enrollment ,0 作为 smart_sales ,0 作为 smart_paid_sales FROM digital.uhg_mr_is_search ds -- IScampaign-to-source_code 映射器 左连接 uhg_part_b.v_is_search_manual_dims_dedupe search_codes_map ON ds.campaign = search_codes_map.campaign_name -- 引入州首字母缩写词 -- Yang:请注意,在极少数情况下,我们在原始数据中没有州名但有 DMA 名。没有将它们映射到状态,因为我们在 reftables 中没有 dma id 映射器
左加入 reftables.us_states state_map ON ds.state_name = state_map.state_name 左加入 reftables.zip_dma_map zip_map ON RIGHT(ds.dma_region_id,3)= zip_map.dma_code -- 左连接 reftables.dcm_dma_map DMA ON dma.dma_code = map.dma_code

WHERE from_date >= '2018-07-01' 分组 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17) 按 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 分组

;

【问题讨论】:

    标签: sql amazon-redshift aginity


    【解决方案1】:

    为什么不直接使用replace()

    select replace(replace(dma, '"', ''), '=') as dma_type_a
    

    【讨论】:

    • 谢谢戈登。对于其他尝试使用它的人,如果您尝试与其他代码连接,我建议使用 CAST 将其转换为整数。
    猜你喜欢
    • 2021-02-10
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多