I wasn't able to get the answer I was looking for here so I posted the question on the Oracle forums. The answer I got was exactly what I was looking for. The following query gets the answer with only one pass through the table and without any joins...
SELECT pid,
MAX(CASE
WHEN value_date > TRUNC (SYSDATE) - 6 THEN my_value
ELSE 0
END)
max_7_days,
MAX(value_date)
KEEP (DENSE_RANK FIRST ORDER BY
(CASE
WHEN value_date >
TRUNC (SYSDATE) - 6
THEN
my_value
ELSE
0
END) DESC)
day_7_days,
MAX(CASE
WHEN value_date > TRUNC (SYSDATE) - 29 THEN my_value
ELSE 0
END)
max_30_days,
MAX(value_date)
KEEP (DENSE_RANK FIRST ORDER BY
CASE
WHEN value_date >
TRUNC (SYSDATE) - 29
THEN
my_value
ELSE
0
END DESC)
day_30_days
FROM my_table
GROUP BY pid;
Incase anyone would like to test it, here is some sample data.
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 300, '18-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 200, '17-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 4500, '16-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 800, '15-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 12000, '14-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 21000, '13-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 5600, '12-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 18400, '11-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 7200, '10-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 24000, '09-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 8800, '08-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 6000, '07-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 44200, '06-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 2800, '05-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 58500, '04-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 8000, '03-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 30600, '02-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 7200, '01-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 62700, '31-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 48000, '30-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 16800, '29-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 83600, '28-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 18400, '27-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 16800, '26-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 40000, '25-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 23400, '24-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 99900, '23-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 67200, '22-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 5800, '21-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 57000, '20-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 96100, '19-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 64000, '18-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 52800, '17-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 71400, '16-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 14000, '15-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 7200, '14-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 111000, '13-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 64600, '12-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 113100, '11-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (1, 84000, '10-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 6000, '18-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 7800, '17-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 13500, '16-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 25600, '15-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 276000, '14-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 210000, '13-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 162400, '12-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 36800, '11-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 86400, '10-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 480000, '09-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 8800, '08-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 102000, '07-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,1237600, '06-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 61600, '05-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,1287000, '04-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 144000, '03-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 275400, '02-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 93600, '01-FEB-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,1630200, '31-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,1248000, '30-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 235200, '29-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,3176800, '28-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 73600, '27-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 403200, '26-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 200000, '25-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 280800, '24-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 599400, '23-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,1612800, '22-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 110200, '21-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,1653000, '20-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,2498600, '19-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,2368000, '18-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 211200, '17-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,2570400, '16-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 224000, '15-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 223200, '14-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2, 999000, '13-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,2325600, '12-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,1017900, '11-JAN-10');
INSERT INTO my_table (pid, my_value, value_date) VALUES (2,2352000, '10-JAN-10');
Thank you all for your efforts in answering this question!
Kal