title: Case When Distinct value then sum another value?
body: <p>Piggy backing off another question I had yesterday.  </p>
  
  <p>I was wondering how I would go about counting the distinct number of records that have an amt > 1500.  The way my data is joined, I could have the same PKey AcctNo reflected more than one time because my full outer joined to another table that has multiple transactional records.  </p>
  
  <pre><code>(Case When AcctNo_PKey = distinct then sum(case when amount &gt; 1500 then 1 else 0 end)
   else 0) end as GT1500
  </code></pre>
  
  <p>this my current code that produces a desired result.  I </p>
  
  <pre><code>SELECT sum(case when amount &gt; 1500 then 1 else 0 end) as GT1500
       , sum(case when amount &lt; 1500 then 1 else 0 end) as LT1500
      , DATEPART(Year, amount.Date) Deposit_Year
      , DATEPART(QUARTER, amount.Date) Deposit_Qtr 
  From account 
  full outer JOIN amount ON account.AcctNo = amount.AcctNo
  group by DATEPART(Year, amount.Date)
      , DATEPART(QUARTER, amount.Date)
  </code></pre>
  
  <p>Or maybe my entire approach is wrong...idk</p>