title: Calculate difference between yesterday' sales using LAG function
body: <p>I'm trying to get the difference between yesterday's sales with the function LAG
  I'm using MySQL, but my problem is that I'm getting null values.</p>
  <p>Here's my query</p>
  <pre><code>select to_char(purchase_date, 'YYYY-MM-DD') as &quot;date&quot;, 
  item,
  brand,
  sales
  from consolidated_purchases
  where purchase_date &gt;='2022-05-05' and purchase_date &lt;'2022-05-07'
  LAG(sales,1) over (partition by &quot;date&quot;, item, brand order by sales) 
  </code></pre>
  <p>I'm not sure if I'm using correctly the partition clause.
  My goal is to be able to create a report that can be sent automatically just when sales of a particular product are lower than 20% of yesterday's sales.</p>
  <p><a href="https://i.stack.imgur.com/6KYnt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6KYnt.png" alt="database sample" /></a></p>