我有以下查询,
SELECT v.pattern_id,
v.id,
v.pdb_id AS viocardId,
p.pdb_id AS PID,
s.vio_id AS SiVioId,
r.date AS orcdate,
s.created_date AS sivcreateddate,
r.job_id,
r.maskset,
r.device,
d.tech_geometry,
r.layer,
r.layer_rev,
r.ptrf,
r.operation,
Concat_ws('_', d.tech_geometry, r.layer, p.pdb_id) AS techlayer
FROM orc_orcviolation v,
orc_orcpattern p,
siverify_siverifyverificationsite s,
orc_orccheck o,
orc_orcrecord r,
siverify_siverifyverificationdevice d
WHERE v.pattern_id = p.id
AND p.pdb_id = s.pattern_id
AND p.if_target = s.if_target
AND p.if_secure <> 1
AND s.create_status <> 5
AND v.check_id = o.id
AND o.record_id = r.id
AND d.id = s.si_device_id
AND r.maskset <> 'MT23RUN1'
AND r.maskset <> 'M25RUN3'
AND r.ptrf NOT LIKE '%PTRF-20251-%'
AND d.fab LIKE '%FAB 1%'
AND v.id > (SELECT v1.id
FROM orc_orcviolation v1,
orc_orcpattern p1,
siverify_siverifyverificationsite s1,
orc_orccheck o1,
orc_orcrecord r1,
siverify_siverifyverificationdevice d1
WHERE v1.pattern_id = p1.id
AND p1.pdb_id = s1.pattern_id
AND p1.if_target = s1.if_target
AND p1.if_secure <> 1
AND s1.create_status <> 5
AND v1.check_id = o1.id
AND o1.record_id = r1.id
AND d1.id = s1.si_device_id
AND r1.maskset <> 'MT23RUN1'
AND r1.maskset <> 'M25RUN3'
AND r1.ptrf NOT LIKE '%PTRF-20251-%'
AND d1.fab LIKE '%FAB 1%'
AND v1.id = s1.vio_id
AND s1.vio_id = s.vio_id)
AND r.date > s.created_date;
我需要的是,我需要为列r.job_id获取不同的值。我对上述查询的输出看起来像是
pattern_id id viocardId PID SiVioId orcdate sivcreateddate job_id maskset device tech_geometry layer layer_rev ptrf operation techlayer
702627 2038025 8270564 4298455 1939970 4/16/2016 12:22 12/23/2015 1:14 442896 MPW2202 MPW2202_TEG1 0.022UM RX AZ PTRF-45862-2896 orc 0.022UM_RX_4298455
702627 2038027 8270566 4298455 1939970 4/16/2016 12:22 12/23/2015 1:14 442896 MPW2202 MPW2202_TEG1 0.022UM RX AZ PTRF-45862-2896 orc 0.022UM_RX_4298455
702627 2038029 8270568 4298455 1939970 4/16/2016 12:22 12/23/2015 1:14 442896 MPW2202 MPW2202_TEG1 0.022UM RX AZ PTRF-45862-2896 orc 0.022UM_RX_4298455
702627 2112780 8425263 4298455 1939970 6/12/2016 4:08 12/23/2015 1:14 471956 ECLIPS4 ECLIPS4_SLM11 0.022UM RX AZ PTRF-45862-3249 orc 0.022UM_RX_4298455
702627 2112783 8425266 4298455 1939970 6/12/2016 4:08 12/23/2015 1:14 471956 ECLIPS4 ECLIPS4_SLM11 0.022UM RX AZ PTRF-45862-3249 orc 0.022UM_RX_4298455
702627 2112784 8425267 4298455 1939970 6/12/2016 4:08 12/23/2015 1:14 471956 ECLIPS4 ECLIPS4_SLM11 0.022UM RX AZ PTRF-45862-3249 orc 0.022UM_RX_4298455
702627 2240805 8558618 4298455 1939970 8/27/2016 8:35 12/23/2015 1:14 504071 ECLIPS4 ECLIPS4_SLM11 0.022UM RX AY PTRF-45862-3610 orc 0.022UM_RX_4298455
702627 2240807 8558620 4298455 1939970 8/27/2016 8:35 12/23/2015 1:14 504071 ECLIPS4 ECLIPS4_SLM11 0.022UM RX AY PTRF-45862-3610 orc 0.022UM_RX_4298455
在上面的操作中,对于PID(4298455),我们可以看到三个job_id(442896,471956,504071)。我想删除job_ids的重复,理想情况下我的操作应该是,
pattern_id id viocardId PID SiVioId orcdate sivcreateddate job_id maskset device tech_geometry layer layer_rev ptrf operation techlayer
702627 2038025 8270564 4298455 1939970 4/16/2016 12:22 12/23/2015 1:14 442896 MPW2202 MPW2202_TEG1 0.022UM RX AZ PTRF-45862-2896 orc 0.022UM_RX_4298455
702627 2112780 8425263 4298455 1939970 6/12/2016 4:08 12/23/2015 1:14 471956 ECLIPS4 ECLIPS4_SLM11 0.022UM RX AZ PTRF-45862-3249 orc 0.022UM_RX_4298455
702627 2240805 8558618 4298455 1939970 8/27/2016 8:35 12/23/2015 1:14 504071 ECLIPS4 ECLIPS4_SLM11 0.022UM RX AY PTRF-45862-3610 orc 0.022UM_RX_4298455
我不认为仅为r.job_id的不同值创建子查询是明智的选择,因为它可能会干扰查询的其他部分。有什么办法吗?提前谢谢。
答案 0 :(得分:0)
您可以尝试更新查询
SELECT v.pattern_id,
MIN(v.id),
MIN(v.pdb_id) AS viocardId,
p.pdb_id AS PID,
s.vio_id AS SiVioId,
r.date AS orcdate,
s.created_date AS sivcreateddate,
r.job_id,
r.maskset,
r.device,
d.tech_geometry,
r.layer,
r.layer_rev,
r.ptrf,
r.operation,
Concat_ws('_', d.tech_geometry, r.layer, p.pdb_id) AS techlayer
FROM orc_orcviolation v,
orc_orcpattern p,
siverify_siverifyverificationsite s,
orc_orccheck o,
orc_orcrecord r,
siverify_siverifyverificationdevice d
WHERE v.pattern_id = p.id
AND p.pdb_id = s.pattern_id
AND p.if_target = s.if_target
AND p.if_secure <> 1
AND s.create_status <> 5
AND v.check_id = o.id
AND o.record_id = r.id
AND d.id = s.si_device_id
AND r.maskset <> 'MT23RUN1'
AND r.maskset <> 'M25RUN3'
AND r.ptrf NOT LIKE '%PTRF-20251-%'
AND d.fab LIKE '%FAB 1%'
AND v.id > (SELECT v1.id
FROM orc_orcviolation v1,
orc_orcpattern p1,
siverify_siverifyverificationsite s1,
orc_orccheck o1,
orc_orcrecord r1,
siverify_siverifyverificationdevice d1
WHERE v1.pattern_id = p1.id
AND p1.pdb_id = s1.pattern_id
AND p1.if_target = s1.if_target
AND p1.if_secure <> 1
AND s1.create_status <> 5
AND v1.check_id = o1.id
AND o1.record_id = r1.id
AND d1.id = s1.si_device_id
AND r1.maskset <> 'MT23RUN1'
AND r1.maskset <> 'M25RUN3'
AND r1.ptrf NOT LIKE '%PTRF-20251-%'
AND d1.fab LIKE '%FAB 1%'
AND v1.id = s1.vio_id
AND s1.vio_id = s.vio_id)
AND r.date > s.created_date;
GROUP BY
v.pattern_id,
PID,
SiVioId,
orcdate,
sivcreateddate,
r.job_id,
r.maskset,
r.device,
d.tech_geometry,
r.layer,
r.layer_rev,
r.ptrf,
r.operation,
techlayer