title: I have my data in postgres database. Sample data and required output should look like below
body: <p><a href="http://i.stack.imgur.com/r3dGN.png" rel="nofollow">enter image description here</a></p>
  
  <p>I am having a very hard time in figuring this out. Can some one please look at the picture and provide a solution.
  Please don't give a solution that involves coding in any scripting languages because I am not a programming guy.
  I want to solve this through sql query(postgres) or using excel formulas in excel.</p>