Sum distinct records in a table with duplicates in Teradata
<p>I have a table that has some duplicates. I can count the distinct records to get the Total Volume. When I try to Sum when the <code>CompTia</code> Code is <code>B92</code> and run distinct is still counts the dupes.</p>

<p><strong>Here is the query:</strong></p>

<pre><code>select 
a.repair_week_period,
count(distinct a.notif_id) as Total_Volume,
sum(distinct case when a.header_comptia_cd = 'B92' then 1 else 0 end) as B92_Sum 
FROM artemis_biz_app.aca_service_event a
where a.Sales_Org_Cd = '8210'
and a.notif_creation_dt &gt;= current_date - 180
group by 1
order by 1
;
</code></pre>

<p>Is There a way to only SUM the distinct records for B92?</p>

<p>I also tried inner joining the table on itself by selecting the distinct notification id and joining on that notification id, but still getting wrong sum counts.</p>

<p>Thanks!</p>