sql 遇到多个重复列名报错:Ambiguous column reference ***

1.执行下段sql报错,原因是a表和b表都有user_log_acct,item_third_cate_cd,它不会自动合并一列的!!只会有两列都叫这个,故c表里有两列user_log_acct,没办法和d表匹配上!

SELECT
    *
FROM
    (
        SELECT
            *
        
        from
            (
                select
                    *
                from
                    表1
                where
                    dt = '2018-05-30'
                    and tp = '13252'
                    and pv_15 > 1
            )a
        LEFT  JOIN
            (
                select
                    *
                from
                    表2
                where
                    dt = '2018-05-30'
                    and item_third_cate_cd = '13252'
                    and order_7 > 0
            )b
        ON
            (
                a.user_log_acct =  b.user_log_acct
                and a.item_third_cate_cd =  b.item_third_cate_cd
               
            )
        WHERE
            b.user_log_acct is NULL
    )c
LEFT  JOIN
    (
        select
            user_log_acct,
            item_third_cate_cd,
            1 as label
        from
            表3
        where
            dt = '2018-06-04'
            and item_third_cate_cd = '13252'
            and order_5 > 0
    )d
ON
    (
        c.user_log_acct =  d.user_log_acct
        and c.cateId =  d.item_third_cate_cd
    )
where
   d.user_log_acct is not NULL
and d.item_third_cate_cd is not null

2.后来尝试在a表取别名,发现也不行,因为这意味有三列user_log_acct,只不过有一列叫pin,其他两列还是重名的!这个问题就不太好解决,除非你把2000多个特征(除了user_log_acct)都列出来

(
                select
                    a.user_log_acct as pin,a.*,b.*
                from
                    表1
                where
                    dt = '2018-05-30'
                    and tp = '13252'
                    and pv_15 > 1
            )a
3.最后解决:在python中写spark sql,在a和b关联后,用drop函数去除b表中重复列
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值