我在这里遇到了问题。
我想根据该列的最大值(时间戳)选择一列,但我一直在检索它。假设我有以下数据:
Comments
========
abcd 2012/08/14 8:03:03 AM more data inside <- I want to retrieve this
hshsh 2012/08/13 1:03:03 AM some other comments
hahhah 2012/08/10 8:03:03 PM test it.
检索max(时间戳)的我的SQL是
select max(substr(comments, instr(comments, '2012'), instr(comments, 'M') - 6)) from TABLEA
但如何根据此声明选择此列?
修改
是否可以这样做:
select comments from tableA where comments like (select max(substr(comments, instr(comments, '2012'), instr(comments, 'M') - 6)) from TABLEA)
我希望得到评论栏的第一行,但没有输出。 我希望我不会太模糊......我正在使用Oracle SQL。
答案 0 :(得分:0)
尝试:
select *
from
(
select comments
from TABLEA
order by substr(comments, instr(comments, '2012'), instr(comments, 'M') - 6) desc
)
where rownum = 1
答案 1 :(得分:0)
您可以尝试:
select
comments, substr(comments, instr(comments, '2012'), instr(comments, 'M') - 6) YEAR
from TABLEA
order by substr(comments, instr(comments, '2012'), instr(comments, 'M') - 6) desc
where rownum = 1