title: SQL Cursor - Count Each Occurrence in Group
body: <p>Been out of the SQL world for a minute and need to know how I can change the below code to count each occurrence where code = 0 in each group where the id is the same and then proceed to the next group of id's.</p>
  
  <p>Basically, I need a count of how many orders with the same id have more than one occurrence of code being 0.</p>
  
  <p>Sample Data:</p>
  
  <pre><code>+------+------+
  |  ID  | CODE |
  +------+------+
  | 1234 |    0 |
  | 1234 |    1 |
  | 1234 |    3 |
  | 1234 |    0 |
  | 1234 |    2 |
  | 5678 |    0 |
  | 5678 |    1 |
  | 5678 |    2 |
  +------+------+
  </code></pre>
  
  <p>My goal would give me a count of "1" for the above sample data.</p>
  
  <pre><code>Declare
  n_id NUMBER;
  n_code NUMBER;
  N_COUNT NUMBER:=0;
  
  cursor dups is
  select id, code 
  from process;
  
  BEGIN
  
  OPEN DUPS; 
  
  LOOP
  
  FETCH DUPS INTO N_ID, N_CODE;
  
  EXIT WHEN DUPS%NOTFOUND;
  
    IF n_code = 0 THEN
      N_COUNT := N_COUNT +1;
    END IF;
  
  END LOOP;
  
    IF N_COUNT &gt; 1 THEN
     dbms_output.put_line ('Record: ' || n_count);
    END IF;
  
  CLOSE DUPS;
  
  END;
  </code></pre>