문제

I have a varchar column that contains data like '0 03-03-14', '1 04-03-14' and so on. I need to select the maximum one, in that case '1 04-03-14'.

My problem is that I can have the '1' (the max value) but how do I have to do if I also want the date ?

For now, I have this :

SELECT MAX(TO_NUMBER(SUBSTR(revision, 1, INSTR(revision, ' ')-1)))
    FROM table
    WHERE name = 'aname'
        AND t_name = 'tname'
    GROUP BY revision

Does anyone have an idea ?

Thanks

올바른 솔루션이 없습니다

다른 팁

I assume you want something like max(version, date version), try this:

Select * from (
  Select * from (
    SELECT
        TO_NUMBER(SUBSTR(revision, 1, INSTR(revision, ' ')-1)) as rev
      , TO_DATE(SUBSTR(revision, 1, INSTR(revision, ' ')+1),'DD-MM-YY') as revDate
    FROM table
    WHERE name = 'aname'
    AND t_name = 'tname'
  ) extracted
  order by extracted.revDate, extracted.rev desc
) where rownum = 1

Do you mean this?

select max(revision)
from table
where name = 'aname' and t_name = 'tname';

It seems strange to put the revision number and date in one column. Is that really your data format? If not, modify your question with the actual data format.

Regarding your answers, I think the best solution would be to split those two parts :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top