SQL: help creating pivot table in oracle for an ID with multiple rows and each containing a date

Viewed 27

I have a table that contains an ID column and a date column in it. The ID can be used in multiple rows but has one DATE per row.

For example:

ID   Date
1    01/01/2015
1    02/01/2015
1    03/01/2014
2    01/01/2014
3    02/01/2015
3    01/01/2014

I would like to get:

ID   DATE         DATE        DATE
1    01/01/2015   02/01/2015  03/01/2014
2    01/01/2014   NULL        NULL
3    02/01/2015   01/01/2014  NULL

The goal of this is to find the IDs that only have dates < 2015.

If I leave the table as original and just do a 'where date < 2015', then I'll get the rows where its correct; but I don't want to see the rows where the same ID also has >= 2015.

1 Answers
select   ID
from     t
group by ID
having   max("Date") < date '2015-01-01'
ID
2

Fiddle

Related