此请求向我提供EMAIL发生的请求发生次数。
select count(*)
from ADRESS K left outer join ADRESS L
on K.LFDNRSECONDADRESS=L.LFDNR
left outer join ADRESS V
on K.VERLFDNR=V.LFDNR
where ((UPPER(K.EMAIL)= 'my@email.com'
or exists (select ADRESSEMAILADR.LFDNR
from ADRESSEMAILADR
where ADRESSEMAILADR.ADRESSLFDNR=K.LFDNR
and UPPER(ADRESSEMAILADR.EMAIL)=
'my@email.com' )
)) and K.ART='K'
但我也希望得到所有出现的“LFDNR”列。
喜欢
3
1234
2345
3456
...
所以第一个是计数,后续是LFDNR = X的所有列的结果。
我试过的原因
LFDNR, select count(*)
K.LFDNR, select count(*)
依旧...... 到目前为止没有运气。
答案 0 :(得分:2)
如果我理解正确,您需要group by
:
select k.LFDNR, count(*)
from ADRESS K left outer join
ADRESS L
on K.LFDNRSECONDADRESS = L.LFDNR left outer join
ADRESS V
on K.VERLFDNR = V.LFDNR
where (UPPER(K.EMAIL)= 'my@email.com' or
exists (select ADRESSEMAILADR.LFDNR
from ADRESSEMAILADR
where ADRESSEMAILADR.ADRESSLFDNR = K.LFDNR and
UPPER(ADRESSEMAILADR.EMAIL) = 'my@email.com'
)
) and
K.ART = 'K'
group by k.LFDNR;