title: SUM(SALARY) when ID is distinct
body: <p>I am having trouble trying to solve this problem, I would like to only add a salary up if the 
  employee's id is distinct. I thought I could do this using the decode() function but I am having trouble defining an expression suitable. I was aiming for something like </p>
  
  <pre><code>SUM(DECODE(S.ID,IS DISTINCT,S.SALARY))
  </code></pre>
  
  <p>But this isn't going to work!</p>
  
  <p>So the full query looks like</p>
  
  <pre><code>SELECT B.ID, SUM(S.SALARY), COUNT(DISTINCT S.ID), COUNT(DISTINCT RM.MEMBER_ID)
  FROM BRANCH B 
  INNER JOIN STAFF S ON S.BRANCH_ID = B.ID
  INNER JOIN RECRUIT_MEMBER RM ON RM.BRANCH_ID = B.ID
  GROUP BY B.ID;
  </code></pre>
  
  <p>But the problem is with <code>SUM(S.SALARY)</code> it's adding up salaries from duplicate ID's</p>