title: How to aggregate by values represented in multiple columns with postgresql
body: <p>I am using postgresql 8.3.23<br />
  I have a table where an ip is represented into 3 different columns.
  What is the best way to aggregate by IP and get sum by column without using multiple joins and multiple queries ?</p>
  <p>table</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">source</th>
  <th style="text-align: center;">trans</th>
  <th style="text-align: right;">dest</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">ip1</td>
  <td style="text-align: center;"></td>
  <td style="text-align: right;">ip2</td>
  </tr>
  <tr>
  <td style="text-align: left;">ip1</td>
  <td style="text-align: center;">ip1</td>
  <td style="text-align: right;">ip3</td>
  </tr>
  <tr>
  <td style="text-align: left;">ip1</td>
  <td style="text-align: center;">ip2</td>
  <td style="text-align: right;">ip3</td>
  </tr>
  <tr>
  <td style="text-align: left;">ip2</td>
  <td style="text-align: center;">ip4</td>
  <td style="text-align: right;">ip5</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>what I am trying to get</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">ip</th>
  <th style="text-align: center;">source</th>
  <th style="text-align: center;">trans</th>
  <th style="text-align: center;">dest</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">ip1</td>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">0</td>
  </tr>
  <tr>
  <td style="text-align: center;">ip2</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">1</td>
  </tr>
  <tr>
  <td style="text-align: center;">ip3</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: center;">2</td>
  </tr>
  <tr>
  <td style="text-align: center;">ip4</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">0</td>
  </tr>
  <tr>
  <td style="text-align: center;">ip5</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: center;">1</td>
  </tr>
  </tbody>
  </table>
  </div>