1

Can any body help me to solve this:

 Value  Date

 1000   01-jan-12
 ............
 1000   01-apr-13

My Aim is to calculate the sum of marks which secured from current month and year APRIL-13 to Previous one year from Current Month and Year.

1 Answer 1

0

your example data shows more that one year from apr 2013.

assuming you wanted to go back to apr-2012

select sum(value)
  from your_tab
 where date >= add_months(trunc(sysdate, 'mm', -12) -- from 1st apr 2012
   and date < trunc(sydate, 'mm');-- anytime up to the end of mar 2013

if you wanted to go back to jan of the prior year, then

select sum(value)
  from your_tab
 where date >= trunc(add_months(trunc(sysdate, 'mm', -12), 'yy') -- from 1st jan 2012
   and date < add_months(trunc(sydate, 'mm'), 1); -- anytime up to the end of apr 2013
1
  • Thanks for your solution, But my input in April 2013, but query should calculate from April-2012 to March-2013, It should not include April 2013, Can you give me the solution for this
    – Sajini
    Apr 9, 2013 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.