title: Sum quantities for products
body: <p>I'm trying to sum specific quantities of products but in my code, when I sum, it takes all quantities I have in my table and brings the full quantity FOR ALL PRODUCTS. Here's the example of the results...</p>
  
  <pre><code>CÓDIGO  QTD
  288     1,153
  63064   1,153
  28229   1,153
  </code></pre>
  
  <p>Should be for example:</p>
  
  <pre><code>CÓDIGO  QTD
  288     12
  63064   9
  28229   231
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre><code>SELECT
     substr(ML.msg, (instr(ML.msg, ' ', 1, 3) + 1), (instr(ML.msg, ' ', 1, 4) - 1) - instr(ML.msg, ' ', 1, 3)) Código,
     (SELECT
              SUM(to_number(substr(ML.msg, -9))) soma
          FROM Msg_log ML,
              item_cbo IC
          WHERE TRUNC(ML.create_date_time) = TRUNC(current_date)
          AND IC.Item_name = substr(ML.msg, (instr(ML.msg, ' ', 1, 3) + 1), (instr(ML.msg, ' ', 1, 4) - 1) - instr(ML.msg, ' ', 1, 3))
          AND ((ML.msg_id = 1053
          AND ML.module = 'WAVE')
          OR (ML.msg_id = 1054
          AND ML.module = 'WAVE')))
      qtd
  FROM Msg_log ML,
      item_cbo IC   
  WHERE TRUNC(ML.create_date_time) = TRUNC(current_date)
  AND ((ML.msg_id = 1053
  AND ML.module = 'WAVE')
  OR (ML.msg_id = 1054
  AND ML.module = 'WAVE'))
  </code></pre>