【问题标题】:Oracle Sql finding duplicates and selecting column value to pivot on this rowOracle Sql 查找重复项并选择要在该行上旋转的列值
【发布时间】:2016-04-01 12:09:40
【问题描述】:

如何根据某些列找到重复项并获取不相似的值并将其添加到一行。

基本上

Last Name, House Number, Name, hobby
Scott,      100,         Peter, chess
Scott,      100,         John, scrabble

我现在想创建一个临时表并执行此操作

Last Name, House Number, Name, Name2, hobby
Scott,     100,          Peter, John, chess

注意:数据库中可以有两个以上的名称。但我们只想要国际象棋/拼字游戏爱好对。临时表应该只有一个爱好(与名字相关但无关紧要),另一个可以推断。

最有效的方法是什么

此表可以滚动浏览大约 1 亿条记录。 (按日期索引,每个日期可以有1亿条记录)。我觉得旋转可能有用,但可能太贵了?

【问题讨论】:

  • 你关心的只有两个名字吗?一个表必须有特定的列。

标签: sql oracle oracle11g oracle-sqldeveloper


【解决方案1】:
select coalesce(t1.LastName, t2.LastName),
       coalesce(t1.HouseNumber, t2.HouseNumber),
       t1.Name, t2.Name, coalesce(t1.hobby, t2.hobby)
from (select * from tablename where hobby = 'chess') t1
full outer join
     (select * from tablename where hobby = 'scrabble') t2
  using (LastName,HouseNumber)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-20
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    相关资源
    最近更新 更多