title: Sum a column multiple times based on different requirements from another column in one select statement?
body: <p>I want to sum the invoices based on the state column.
  But i dont want to do 50 select statements. and the amount of states I query could vary<br>
  My Table</p>
  <pre><code>|invoice|state|
  | 123   | NY  |
  | 241   | VA  |
  | 533   | WA  |
  
  </code></pre>
  <p>Can I do something like this:</p>
  <pre><code>$sql=&quot;Select SUM(invoice) where state=NY as NY AND where state=VA as VA&quot;;
  $stmt = $conn-&gt;prepare($sql);
  $stmt-&gt;execute();
  $stmt-&gt;bind_result($ny,$va);
  $stmt-&gt;fetch();
  echo $ny;
  echo $va;
  //result: 123 241
  </code></pre>
  <p>Any ideas would be great! Do I have to make a select statement that executes in a for loop for each state in the array?
  thanks!</p>