title: R, SQL query in for loop
body: <p>I have a list that contains customers and their ID. It looks like the one below:</p>
  
  <pre><code>customers_id &lt;- list(x = John(1,2,3), Rick = c(4), Sam = c(5,6))
  </code></pre>
  
  <p>and a database that looks like the one below and calls 'db'</p>
  
  <pre><code>date        id   value
  2017-05-12  1      51 
  2017-05-13  2      3  
  2017-05-14  3      217
  2017-05-15  1      12
  2017-05-16  2      98
  2017-05-17  3      123
  2017-05-18  1      78
  2017-05-19  2      36
  2017-05-20  4      178
  2017-05-18  5      728
  2017-05-19  6      336
  2017-05-20  4      718
  2017-05-18  5      758
  2017-05-19  6      366
  2017-05-20  4      787
  </code></pre>
  
  <p>I tried to make a for loop but couldn't figuer out the right solution. I think that in the loop should be a query that
  will take a correct ID and sum values for ID</p>
  
  <pre><code>corect_values &lt;- paste(" SELECT date, id, SUM(value) FROM db WHERE id = '", id, "' ")
  </code></pre>
  
  <p>So I have two issues: How to put a query into for loop and how to write a sql query that will take into account all id for customer.</p>
  
  <p>Result should like the one below:</p>
  
  <pre><code>John  618
  Rick  1683
  Sam   2188
  </code></pre>
  
  <p>Do you have any idea how it can be solved ? 
  Thanks for any help !</p>