我想选择最后插入记录的特定列。我怎样才能做到这一点?

时间:2017-09-20 03:09:20

标签: sql oracle greatest-n-per-group

// Read the sentences from the input file and save to original[20].
// Hint: use getline() function.
string line;
while (getline(fin, line)) { // Reading a line from input.txt file
    original[i] = line;
    encrypted[i] = cipher.Encode(original[i]); // Encrypt the sentences and save to encrypted[20]
    decrypted[i] = cipher.Decode(encrypted[i]); // Decrypt the sentences and save to decrypted[20]
    i++;
} 

o / p = select max(created_t) from inv_database ;

78578596

我想合并这两个查询并想要结果。 有4条记录的最大select in_date from inv_database where created_t = 78578596; ,并且所有记录都具有相同的created_t。我想得到该日期。它需要什么查询?

2 个答案:

答案 0 :(得分:1)

使用子查询:

select in_date
from inv_database
where created_t = (select max(created_t) from inv_database);

您还可以使用像row_number这样的分析函数:

select t.in_date
from
(
    select in_date,
        row_number() over (order by created_t desc) rn
    from inv_database
) t
where t.rn = 1;

答案 1 :(得分:0)

SubQuery将帮助您......

select in_date as Date
from inv_database
where created_t 
= (select max(created_t) from inv_database);

您可以根据表格列结构进行尝试。