title: count and distinct over multiple columns
body: <p>I have a database table containing two costs. I want to find the distinct costs over these two columns. I also want to find the count that these costs appear. The table may look like</p>
  
  <pre><code>|id|cost1|cost2|
  |1 |50   |60   |
  |2 |20   |50   |
  |3 |50   |70   |
  |4 |20   |30   |
  |5 |50   |60   |
  </code></pre>
  
  <p>In this case I want a result that is distinct over both columns and count the number of times that appears. So the result I would like is</p>
  
  <pre><code>|distinctCost|count|
  |20          |2    |
  |30          |1    |
  |50          |4    |
  |60          |2    |
  |70          |1    |
  </code></pre>
  
  <p>and ideally ordered</p>
  
  <pre><code>|disctinCost1|count|
  |50          |4    |
  |60          |2    |
  |20          |2    |
  |70          |1    |
  |30          |1    |
  </code></pre>
  
  <p>I can get the distinct over two columns by doing something like</p>
  
  <pre><code>select DISTINCT c FROM (SELECT cost1 AS c FROM my_costs UNION SELECT cost2 AS c FROM my_costs);
  </code></pre>
  
  <p>and I can get the count for each column by doing </p>
  
  <pre><code>select cost1, count(*)
  from my_costs 
  group by cost1
  order by count(*) desc;
  </code></pre>
  
  <p>My problem is how can I get the count for both columns? I am stuck on how to do the count over each individual column and then add it up. </p>
  
  <p>Any pointers would be appreciated.</p>
  
  <p>I am using Oracle DB.</p>
  
  <p>Thanks</p>