I have a Expenses table. It maintains the daily expenses in US Dollars of various units of the company.
The structure of the table is
Dept_Id Date Month Year Expense
The data looks like
Dept_id Date Month Year Expense
--------------------------------------------------
10 01/01/2006 1 2006 1000
10 01/02/2006 1 2006 2000
10 02/02/2006 2 2006 6000
10 01/05/2007 1 2007 5000
20 01/01/2006 1 2006 6000
20 01/02/2006 1 2006 8000
20 02/02/2006 2 2006 3000
20 01/05/2007 1 2007 4000
I need the monthly expense and Cumulative monthly expense of each Department . How do I achieve it . The output should look like
Dept_id Year Month Month Exp Cum Monthly Expense
---------------------------------------------------------
10 2006 1 3000 3000
10 2006 2 6000 9000
10 2007 1 5000 14000
20 2006 1 14000 14000
20 2006 2 3000 17000
20 2007 1 4000 21000
The monthly expense column has the sum of all daily expenses for a particular department_id in a particular month and year . The Cumulative Monthly Expense is the cumulative sum of all monthly expenses for a particular department_id .
How do I achieve the output as needed above
Please suggest
The structure of the table is
Dept_Id Date Month Year Expense
The data looks like
Dept_id Date Month Year Expense
--------------------------------------------------
10 01/01/2006 1 2006 1000
10 01/02/2006 1 2006 2000
10 02/02/2006 2 2006 6000
10 01/05/2007 1 2007 5000
20 01/01/2006 1 2006 6000
20 01/02/2006 1 2006 8000
20 02/02/2006 2 2006 3000
20 01/05/2007 1 2007 4000
I need the monthly expense and Cumulative monthly expense of each Department . How do I achieve it . The output should look like
Dept_id Year Month Month Exp Cum Monthly Expense
---------------------------------------------------------
10 2006 1 3000 3000
10 2006 2 6000 9000
10 2007 1 5000 14000
20 2006 1 14000 14000
20 2006 2 3000 17000
20 2007 1 4000 21000
The monthly expense column has the sum of all daily expenses for a particular department_id in a particular month and year . The Cumulative Monthly Expense is the cumulative sum of all monthly expenses for a particular department_id .
How do I achieve the output as needed above
Please suggest