Comparing two date ranges within the same table

前端 未结 2 1788
忘掉有多难
忘掉有多难 2021-01-14 17:42

I have a table with sales per store as follows:

SQL> select * from sales;

        ID ID_STORE DATE       TOTAL
---------- -------- ---------- -----------         


        
2条回答
  •  囚心锁ツ
    2021-01-14 18:41

    I think the problem is in your join condition. I haven't tested it but I think you could try sth like

    ... ON (    sales.id_store = sales2.id_store 
            AND sales.date = ADDDATE(sales2.date, INTERVAL 1 YEAR) 
            ...
           )
    

提交回复
热议问题