0
select sum(case when NumFirstNames <> 1 then 1 else 0 end) as DifferentFirstNames,
sum(case when NumLastNames <> 1 then 1 else 0 end) as DifferentLastNames,
sum(case when NumSSN <> 1 then 1 else 0 end) as DifferentSSN,
sum(case when NumPhone <> 1 then 1 else 0 end) as DifferentPhone
from (select EncounterId, count(*) as Num,
count(distinct FirstName) as NumFirstNames,
count(distinct LastName) as NumLastNames,
count(distinct SSN) as NumSSN,
count(distinct Phone) as NumPhone
from table t
group by EncounterId) e;
我需要上面的查詢來對錶中另一列進行分組,名爲FacilityCode,以及顯示重複EncounterIDs的次數和列沒有缺陷。根據列的相似性檢查所有其他列中的更改(續)
另外,除了計數(即第一個查詢的結果背後的數據)之外,是否可以使用類似構建的查詢來拉取「缺陷」結果?
見鏈接前面的問題: Check for changes in all other columns based on similarities one column
這是我需要的第一部分 - 謝謝你。 –
我所說的「拉出缺陷」的意思是拉取導致DifferentFirstNames,DifferentLastNames等增加的數據(表中不同的數據)。本質上而不是分組查詢,拉* –