Hi sir: I have reproduced the problem you described in my environment. It may be a bug. I will try to find out the root cause.
You can open an issue in JIRA to track this. > 在 2020年5月7日,15:44,欧秋斌 <[email protected]> 写道: > > 您好! > > 我的工作中,由于订单类型的维度标准不是确定的,所以需要在SQL语句中进行定义(如下方第一个公用表达式)。 > 在下面的语句中,进行union all拼接时, > 第二个维度的销售额(val_day)值会出现null。但是单独执行订单类型和日期这两个维度中的任何一个都可以返回结果。唯独两者进行union > all时会出问题。 > 我想了没弄明白,想请教一下大家,这个问题出在哪里 ? > > with cte as( -- 每天和每种订单类型的销售额汇总 > select part_dt, > case when lstg_format_name='Auction' then '一类订单' > when lstg_format_name='FP-non GTC' then '二类订单' > when lstg_format_name='ABIN' then '三类订单' > when lstg_format_name='FP-GTC' then '四类订单' > else '其他订单' end style, > sum(price) val > from kylin_sales_ts2 > group by part_dt, case when lstg_format_name='Auction' then '一类订单' when > lstg_format_name='FP-non GTC' then '二类订单' when lstg_format_name='ABIN' then > '三类订单' when lstg_format_name='FP-GTC' then '四类订单' else '其他订单' end > ) > ,cte2 as( ---- 分别按照订单类型和日期维度 > select part_dt, sum(val)over(partition by style) val_style, > sum(val)over(partition by part_dt) val_day from cte > where part_dt>='201310' > ) > ---- 两种维度结果分别去重后,合并起来 > select part_dt, val_style from cte2 ---- 订单类型维度 > group by part_dt, val_style > > union all > select part_dt, val_day from cte2 ---- 日期维度 > group by part_dt, val_day > > > > > > >
