如果多次找到一个字段,如何不获取数据
How to not get data if a field is found more than once
我从安装和设备编号查询中获得结果,
但是,如果我在安装中有不止一台设备,我想省略该数据。
select a~anlage, c~equnr
from eastl as a
inner join egerh as b on a~logiknr = b~logiknr and a~bis = '99991231' and b~bis = '99991231'
inner join equi as c on b~equnr = c~equnr and c~matnr = 'REGULATOR'
group by a~anlage, c~equnr
having count(*) = 1
我目前的结果是这样的:
anlage - equnr
111111 - 01012
111111 - 01013
111111 - 01014
222222 - 01015
222222 - 01016
444444 - 01017
我希望这样:
anlage - equnr
444444 - 01017
看来你只需要按a~anlage
分组:
select a~anlage, max(c~equnr)
from eastl as a
inner join egerh as b on a~logiknr = b~logiknr and a~bis = '99991231' and b~bis = '99991231'
inner join equi as c on b~equnr = c~equnr and c~matnr = 'REGULATOR'
group by a~anlage
having count(*) = 1
我从安装和设备编号查询中获得结果, 但是,如果我在安装中有不止一台设备,我想省略该数据。
select a~anlage, c~equnr
from eastl as a
inner join egerh as b on a~logiknr = b~logiknr and a~bis = '99991231' and b~bis = '99991231'
inner join equi as c on b~equnr = c~equnr and c~matnr = 'REGULATOR'
group by a~anlage, c~equnr
having count(*) = 1
我目前的结果是这样的:
anlage - equnr
111111 - 01012
111111 - 01013
111111 - 01014
222222 - 01015
222222 - 01016
444444 - 01017
我希望这样:
anlage - equnr
444444 - 01017
看来你只需要按a~anlage
分组:
select a~anlage, max(c~equnr)
from eastl as a
inner join egerh as b on a~logiknr = b~logiknr and a~bis = '99991231' and b~bis = '99991231'
inner join equi as c on b~equnr = c~equnr and c~matnr = 'REGULATOR'
group by a~anlage
having count(*) = 1