I have a table that has transactional data by store number and transaction date. It also includes the year and period number of the corresponding transaction date, as such:
create table transactional_data (
store_id number,
tran_date date,
year number,
period_no number,
orders number,
sales number
);
I need a query that will return a row for every tran_date that includes a sum of orders and sales through that day of the period.
For example, if I had the following in the table:
STORE_ID TRAN_DATE YEAR PERIOD_NO ORDERS SALES
10 2019-01-01 2019 1 10 119.12
10 2019-01-02 2019 1 15 201.56
10 2019-01-03 2019 1 13 167.92
I would want the result of the query to be:
STORE_ID TRAN_DATE YEAR PERIOD_NO ORDERS_PTD SALES_PTD
10 2019-01-01 2019 1 10 119.12
10 2019-01-02 2019 1 25 320.68
10 2019-01-03 2019 1 38 488.60
I can easily accomplish a group by period to give me the total orders and sales for a store for the entire period, but I have not been able to find a way to break out the period to date sales through each transaction date.
How can this be accomplished?