I have this table:
| DAY | TRIMESTER |
Day is an integer value, always increasing (it counts the seconds passing from day 0). TRIMESTER contains a String value ('FIRST','SECOND','THIRD',etc). I need to get the list of trimesters in the right order.
SELECT DISTINCT TRIMESTER FROM table
returns:
| TRIMESTER |
| FIRST |
| THIRD |
| SECOND |
I have assessed that this would solve my problem:
SELECT DISTINCT TRIMESTER, SUM(DAY) FROM table GROUP BY TRIMESTER ORDER BY SUM(DAY)
Is there a nicer solution which would output what I need and that would require less computing done by the database? The database is Oracle 11g and the tables are supposed to become very big.
SAMPLE DATA:
| DAY | TRIMESTER |
| 0 | FIRST |
| 10 | FIRST |
| 12 | FIRST |
| 20 | FIRST |
| 30 | SECOND |
| 35 | SECOND |
| 46 | THIRD |
I need to get in order: 'FIRST','SECOND' and 'THIRD'. Anyway I have no control over the keys in the TRIMESTER column. They are strings and might just be any string, I can't order them by name. I only know that they cover a "range" of DAY values. E.g. if I had values of "DAY" between 31 and 34 in the example, they'd all have a "SECOND" value in the trimester column.