0

我有一个查询如下

select custref, tetranumber 
from
    (select * 
     from cdsheader h, custandaddr c 
     where h.custref=c.cwdocid and c.addresstype = 'C' )
where tetranumber = '034096'

目标是第二列应该只有一个对应的第一列

例如:034096 应该始终将 2600135 作为第一列

我想检查 034096 除了 2600135 之外是否还有任何值。

(我是一名 java 开发人员,并提出了一个解决方案来避免数据的 1 到 n 或 n 到 n 映射,但是 DB(Oracle)中已经有坏数据,所以我想检查是否有坏数据,以便我可以删除数据)

4

2 回答 2

0

回复:目标是第二列应该只有一个对应的第一列 您需要执行一个聚合函数,如 MAX 或 MIN,以确定返回哪一行。

于 2012-11-21T17:05:01.760 回答
0

谢谢各位回复,

我已经找到方法了,就这样……

select custref, count(distinct(tetranumber)) from( select custref, tetranumber from cdsheader h, cusstandaddr c where h.custref=c.cwdocid and c.addresstype = 'C') 按具有 count(distinct(tetranumber)) 的 custref 分组>1

于 2012-11-26T15:53:39.967 回答