title: How can I group amount of sales for the last 30days grouped on a daily basis
body: <p>I am using <code>Microsoft SQL Server</code> and am trying to figure out how to get the total numbers sales for the last 30days on a daily basis.</p>
  <pre><code>declare @startperiod date;
  declare @endperiod date;
  set @startperiod = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-3, 0)   --First day of 3 months ago
  set @endperiod = getdate()-1  
  
  select distinct
  
      sum(salesamount) as TotalSales
  
  from sales
  
  where salesdate between getdate()-30 and getdate()-1
  
  </code></pre>
  <p>The above will only give me the total of sales for the past 30 days as at yesterday. What I would like is the following:</p>
  <pre><code>#Sales_Last30Days | Date as at
  
  120                 19/11/2020
  140                 18/11/2020
  </code></pre>
  <p>Basically what I am showing in the above table is that 30days before till the 19/11/2020 we have 120 sales, similarly 30days before the 18/11/2020 till the 18/11/2020 we have 140 sales.</p>
  <p>I hope someone can help because I have no idea how to go about it.</p>
  <pre><code></code></pre>