【发布时间】:2019-07-13 14:45:33
【问题描述】:
我们如何通过使用 with 子句语句仅选择在某个字段中具有值的那些来消除重复?
查询是这样的:
with x as (--queries with multiple join tables, etc.)
select distinct * from x
下面的输出:
Com_no Company Loc Rewards
1 Mccin India 50
1 Mccin India
2 Rowle China 18
3 Draxel China 11
3 Draxel China
4 Robo UK
如您所见,我得到了重复的记录。我想摆脱不唯一的空值。也就是说,Robo 是独一无二的,因为它在 Rewards 中只有 1 条记录为空值,所以我想保留它。
我试过了:
with x as (--queries with multiple join tables, etc.)
select distinct * from x where Rewards is not null
当然这是不对的,因为它也摆脱了4 Robo UK
预期的输出应该是:
1 Mccin India 50
2 Rowle China 18
3 Draxel China 11
4 Robo UK
【问题讨论】:
-
预期的输出应该是什么?
-
@VamsiPrabhala 嗨,我添加了预期的输出。想知道我们是否仍然可以使用并从 with 子句 population 中选择
标签: sql oracle distinct common-table-expression distinct-values