title: T-SQL: calculate in dependence of the content of a column
body: <p>I want to calculate in T-SQL in dependence of the content of a column, the content of another column should be in the numerator or denominator</p>
  <p>I have a table with the following content:</p>
  <pre><code>+------------+----------+----+-------------------------+  
  | machine-nr | duration | ID | timestamp               |  
  +------------+----------+----+-------------------------+  
  | 1108       | 47       | 11 | 2017-02-11 00:08:15.000 |  
  | 1112       | 195      | 2  | 2017-02-11 00:13:13.000 |  
  | 1108       | 339      | 7  | 2017-02-11 00:13:54.000 |  
  | 1108       | 19       | 2  | 2017-02-11 00:13:54.000 |  
  | 1112       | 20       | 11 | 2017-02-11 00:13:33.000 |  
  +------------+----------+----+-------------------------+  
  </code></pre>
  <p>Now I want to do this sort of calculation</p>
  <p>Every duration with the ID 11 should be in the dividend and the sum of all duration with the IDs 11, 2 and 7 should be in the divisor.</p>
  <p>Something like that (i know it doesn't work that way):</p>
  <pre><code>SUM(duration if ID = 11) / SUM(duration if ID =11) + SUM(duration if ID = 2) + SUM(Duration if ID = 7)
  group by machine-nr
  </code></pre>
  <p>I hope you know what I mean.</p>