title: How to create query for search total sales previous year
body: <p>I have table named Sales.OrderValues that contain of 2 column, namely orderyear and val (total sales per day).</p>
  <p>This is the record snippet (I cant show all of record because there are 830 rows)</p>
  <p><a href="https://i.stack.imgur.com/6dNB8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6dNB8.png" alt="Sales.OrderValues" /></a></p>
  <p>I want to show the result like this</p>
  <p><a href="https://i.stack.imgur.com/woxUE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/woxUE.png" alt="Expected result" /></a></p>
  <p>But, my output is different with my expected output.</p>
  <p><a href="https://i.stack.imgur.com/HcFQV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HcFQV.png" alt="My output" /></a></p>
  <p>As you can see, the expected output of prevtotalsales in 2008 is 618085.30. But, my output is 825169.29 (which is 208083.99 + 617085.30).</p>
  <p>Below is my query</p>
  <pre><code>SELECT
     YEAR(D1.orderdate) AS orderyear,
     SUM(D1.val) AS curtotalsales,
     (
        SELECT
           SUM(D2.val) 
        FROM
           Sales.OrderValues D2 
        WHERE
           YEAR(D1.orderdate) &gt; YEAR(D2.orderdate)
     )
     AS prevtotalsales 
  FROM
     Sales.OrderValues D1 
  GROUP BY
     YEAR(D1.orderdate);
  </code></pre>
  <p>How to show the SUM of totalsales at the previous year without adding the next year's totalsales?</p>