Hello All,
I have data that looks like this.
PLAN PLAN_INSTANCE DATE_START DATE_END TOTALS
1007 1 20150101 20151231 10
1007 2 20140101 20141231 25
1007 3 20130101 20131231 12
1008 1 20150101 20151231 22
1008 2 20140101 20141231 9
I would like run a query that displays one row per plan based on max(date_start).
i have tried
select plan, t.date_start, date_end, totals
from t_totals t
where t.date_start= (select max(date_start)
from t_totals
where date_start= t.date_start);
but this doesn't seem to work as i get all the 5 rows instead of 2 rows.
Can you suggest me how i can modify my query?
Here is the table information
CREATE TABLE T_TOTALS
(
PLAN NUMBER(9) NOT NULL,
PLAN_INSTANCE NUMBER(4) NOT NULL,
DATE_START NUMBER(8) NOT NULL,
DATE_END NUMBER(8) NOT NULL,
TOTALS NUMBER(9) NOT NULL,
);
CREATE UNIQUE INDEX I_TOTALS ON T_TOTALS
(SAK_PUB_HLTH, SAK_SHORT);
CREATE INDEX X_TOTALS_1 ON T_TOTALS
(SAK_PUB_HLTH, DTE_EFFECTIVE);
Thanks in advance,
sqlamateur