title: Get the sum of all rows only once per userid
body: <p>I am getting the sum of all the rows in <code>registration</code> table. Table structure looks like this:</p>
  
  <pre><code>row_id  row_registration_fee  row_amount  row_class  row_user_id
  1          200                 1000         18           1
  2          200                 2510         18           1
  3            0                 1600         19           2
  4            0                 1500         19           1
  5          200                 1254         19           3
  6          200                 3000         19           1
  7          200                 2000         19           1
  8            0                  100         20           1
  9            0                  300         20           2
  </code></pre>
  
  <p>A user can have multiple registration fee. And I need to get the sum of all the <code>row_registration_fee</code> by <code>row_class</code>. The result should be like this:</p>
  
  <pre><code>row_registration_fee  row_class
         200                18
         400                19
           0                20
  </code></pre>
  
  <p>My select :</p>
  
  <pre><code>SELECT (COUNT(DISTINCT(row_user_id))* 200) as 'fee' 
  FROM registration 
  WHERE row_registration_fee  &gt; 0  
  GROUP BY row_class
  </code></pre>
  
  <p>Is there a better query here that can give a result like the above sample? </p>
  
  <p>The result will be displayed in table rows using foreach loop in PHP. As of now, it will only give me two results for the registration fee, the <code>row_class 18</code>  and <code>row_class 19</code> it excludes the <code>row_class 20</code> because it only selects the user with a fee.</p>
  
  <p><strong>Additional explanation</strong>: The user with 2 or more registration fees should count only as one if the user has a total of 400 fees it should sum only 200.</p>