Home > Mobile >  Records for the last 7 days
Records for the last 7 days

Time:07-20

Using Snowflake, I want to get the daily stock for the last 7 days. Columns I have in this table are: product_ID, date, and quantity

my desired out put should look like the following:

product_ID        DATE            Quantity 
82471             2022-07-14       40
82471             2022-07-15       35
82471             2022-07-16       34
82471             2022-07-17       50
82471             2022-07-18       53
82471             2022-07-19       51
82471             2022-07-20       40

Any ideas how to reach this output? :)

CodePudding user response:

I don't know if you need to aggregate your data, but based on your input, something like this may work:

select product_id, date, Quantity
from mytable
where "DATE" > dateadd( 'days', -7, current_date )
order by product_id, date DESC;
  • Related