title: Comparing two columns in a same table by considering the duplicates
body: <p>I have a sample table as follows.</p>
  
  <pre><code>A      B               C         D
  ------+---------+--------+---------
  3.2   |  India  |  456   |  3.2
  3.2   |  India  |  -67   |  5
  -3.2  |  US     |  -30   |  8
  3.2   |  UK     |  3.9   |  5
  5     |  UAE    |  2.4   |  9
  6     |  UAE    |  5     |  -3.2
  </code></pre>
  
  <p>I would like to first sort the data as shown in the below format. 'B' &amp; 'C' columns are tied to 'D' column such that when I sort 'D' then 'B' &amp; 'C' columns will move accordingly.
  But 'A' is independent </p>
  
  <pre><code>A(ascending)   B           C       D((Descending))
  ------------+-----------+--------+--------
  -3.2        |   UAE     |   2.4  |  9
  3.2         |   US      |  -30   |  8
  3.2         |   India   |  -67   |  5
  3.2         |   UK      |  3.9   |  5
  5           |   India   |  456   |  3.2
  6           |   UAE     |  5     |  -3.2
  </code></pre>
  
  <p>For the table above I would like to get the following as final output (I am ignoring the signs while comparing). 
  In the above table I am Checking 'D' column value in 'A' column(One to One mapping) if it is not their then it should push it down</p>
  
  <pre><code>A(ascending)   B           C       D((Descending))
  ------------+-----------+--------+--------
  -3.2        |   India   |  456   |  3.2
  3.2         |   UAE     |  5     |  -3.2
  3.2         |   null    |  null  |  null
  3.2         |   null    |  null  |  null
  5           |   India   |  -67   |  5
  6           |   null    |  null  |  null 
  null        |   UAE     |   2.4  |  9
  null        |   US      |  -30   |  8
  null        |   UK      |  3.9   |  5
  </code></pre>
  
  <p>FINAL OUTPUT (Values which are pushed down):</p>
  
  <pre><code>null        |   UAE     |   2.4  |  9
  null        |   US      |  -30   |  8
  null        |   UK      |  3.9   |  5
  </code></pre>
  
  <p>It's probably using <code>NOT IN</code>, <code>COUNT</code> and a <code>JOIN</code> but I can't seem to put it together properly (especially since I'm selecting data from the same table). Does any one have an idea about this? Thanks.</p>