in reply to Nested Statement

I don't seem to fully understand your question, namely if the amount is just the value on the record of 'one year back from current date', and it seems that you have quite an amount of date calculations to be made on the conditions to select your records.
It doesn't occur to me any way of doing all that on the same query, and cannot do tests right now.

I would suggest you to do it separately, first get the results for that date range and then, foreach, get the values for a year ago.
One other approach would be to have those calculations on a stored procedure.

update
Though this is not Perl related I found it intriguing and took the challenge to see if I could come up with a solution.
I manage to get hands on a database and do some tests.
-- Create test table create table mmm ( mid number, acount varchar2(10), amount varchar2(10), sdate date ) / commit; -- populate with some records insert into mmm values(1, 'a', '1', sysdate ); insert into mmm values(2, 'a', '3', sysdate - 10); insert into mmm values(3, 'b', '2', sysdate - 1 ); insert into mmm values(5, 'b', '6', sysdate - 11); insert into mmm values(4, 'c', '3', sysdate - 2 ); insert into mmm values(6, 'c', '9', sysdate - 12); insert into mmm values(7, 'd', '1', sysdate - 3 ); insert into mmm values(8, 'e', '1', sysdate - 4 ); commit; -- confirm that the data is there :) select * from mmm; MID ACOUNT AMOUNT SDATE + ---------------------- ---------- ---------- ------------------------- + 1 a 1 26-JAN-08 + 2 a 3 16-JAN-08 + 3 b 2 25-JAN-08 + 4 c 3 24-JAN-08 + 5 b 6 15-JAN-08 + 6 c 9 14-JAN-08 + 7 d 1 23-JAN-08 + 8 e 1 22-JAN-08 + 8 rows selected -- and now work some magic select m1.acount, m1.amount, m1.sdate, m2.amount as "amount 10 days ea +rlier" from mmm m1 left outer join mmm m2 on (m2.acount=m1.acount) where (m1.sdate >=sysdate-3 and m1.sdate<=sysdate) and m2.sdate=(m1.sdate - 10); ACOUNT AMOUNT SDATE amount 10 days earlier + ---------- ---------- ------------------------- ---------------------- + a 1 26-JAN-08 3 + b 2 25-JAN-08 6 + c 3 24-JAN-08 9 + 3 rows selected -- These tests were ran on an Oracle 10g DB