tsql - SQL - Group Value Column A, Only show in Column B has different values -


i trying write query keep eye out when same email address or telephone number being used postcode different.

i have table below:

ref@   | pcode   | email ---------------------------------- lyjx01 | b99 1aa | this@that.com lyjx02 | b98 1aa | this@that.com lyjx03 | b92 1dd | this@that.com ahsf01 | b91 2bb | my@email.com 

i want pull out records this@that.com because have multiple different postcodes associated email address.

in ideal world postcode should unique email address if postcode ever different wish pull policies.

i have far written this:

select pr.b@, pr.ref@, pr.pcode, pr.email dbo.ic_daprospect pr pr.email in ( select email dbo.ic_daprospect pr group pr.email having count(*) > 1 ) 

all doing though pulling records have multiple lines same postcode , email address exists more once.

how go showing have instances of postcode changing?

cheers.

try below along requirement should exclude records email id , code combination same.

  select *     dbo.ic_daprospect pr     exists(                 select 1                 dbo.ic_daprospect pr2                 pr.email=pr2.email , pr.email||pr.pcode <> pr2.email||pr2.pcode                 ) 

hope helps


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -