How to get sum of last previous X days of everyday?
Here is what I think you want,

SELECT days.d::date, sum(sales.number_of_sales)
FROM (
        SELECT min(sales_create_date::date), max(sales_create_date::date)
        FROM sales
) AS minmax
CROSS JOIN LATERAL generate_series(minmax.min, minmax.max, '2 days')
        AS days(d)
LEFT OUTER JOIN sales
        ON sales_create_date &gt;= days.d
        AND sales_create_date &lt; (days.d + '2 days')
GROUP BY days.d;


Notice you have to put the window date twice in the above.

What we're doing is,


Selecting min and max dates for the table
Generating the start for the range on the window
Joining back to sales with the range start and the end interval
Grouping and selecting the count(*) in the window.


Result,

     d      | sum  
------------+------
 2015-05-02 | 1000
 2015-05-04 |  500
 2015-05-08 | 1700
 2015-05-06 | 1300
(4 rows)