title: Table Self Join for Year over Year comparison
body: <p>I am having trouble self joining a table of data to provide year over year results in a single row.</p>
  
  <p>My Data is currently stored as follows in table sales. I can work with either Postgres or sqlite3.</p>
  
  <p>we(date) | store | category | planu | planrev | merchu | merchrev</p>
  
  <p>by desired outcome is:
  <a href="https://i.stack.imgur.com/aFWJE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aFWJE.png" alt="excel mockup"></a></p>
  
  <p>I need to be able to show values for LY for 1/7/17 in the last 4 columns.</p>
  
  <p>I will then union the results with those for all other partners replicating the same query for other tables.</p>
  
  <p>It can be assumed that all current year data will be we>1/1/18 to match the date 364 days ago for previous year results.</p>
  
  <p>Through reading other posts I think I may need to craft a CTE query, I just don't know where to start.</p>
  
  <p>I hope this was clear.</p>
  
  <p>Any help in working this out would be greatly appreciated.</p>