创建唯一表

时间:2015-05-25 17:21:50

标签: sql duplicates

我在识别字段中有一个重复的表。在其他列中,当标识字段重复时,值会有所不同。我想选择其他列的值,使其成为标识字段的新的,不同的表。

我无法使表格具有识别字段的明显选择计数。

XX_DDD1 =不同的识别字段表

POLY_NUMS_FOR_CC_TYPES_V1 =来源表

XX_DD2 =重复多边形

Create table XX_DDD as select
a.Poly_num,
 (CASE WHEN a.poly_num in (select poly_num from XX_DD2) THEN 
        (CASE WHEN b.Status = 'Planned' and b.Ownership = 'David' THEN 'Planned'

              WHEN b.Status = 'Planned' and b.Ownership = 'Peter' THEN 'Planned'
              WHEN b.Status = 'Deferral' and b.Ownership = 'David' THEN 'Deferral'
              WHEN b.Status = 'Deferral' and b.Ownership = 'Peter' THEN 'Deferral'
              WHEN b.Status = 'Deferral' and b.Ownership = 'John' THEN 'Deferral'
        END)
        ELSE b.Status
  END) Status,
  (CASE WHEN a.poly_num in (select poly_num from XX_DD2 ) THEN 
        (CASE WHEN b.Status = 'Planned' and b.Ownership = 'David' THEN 'David'
              WHEN b.Status = 'Planned' and b.Ownership = 'Peter' THEN 'Peter'
              WHEN b.Status = 'Deferral' and b.Ownership = 'David' THEN 'David'
              WHEN b.Status = 'Deferral' and b.Ownership = 'Peter' THEN 'Peter'
              WHEN b.Status = 'Deferral' and b.Ownership = 'John' THEN 'John'
        END)
        ELSE b.Ownership
  END) Ownership
  from POLY_NUMS_FOR_CC_TYPES_V1 b, XX_DDD1 a where a. poly_num = b.poly_num ;

0 个答案:

没有答案