我有桌子,
create table names
(name string,insert_time timestamp)
row format delimited
fields terminated by ','
stored as textfile;
select * from names;
OK
abc 2017-05-06 10:11:30
abc 2017-05-07 11:15:40
pqr 2017-05-06 12:11:10
我想只获取最新插入的数据。 O / P应如下,
abc 2017-05-07 11:15:40
pqr 2017-05-06 12:11:10
请指导如何获得此信息。
答案 0 :(得分:-1)
SELECT * FROM names ORDER BY insert_time DESC LIMIT 2
desc 的顺序将按时间戳按递减顺序对记录进行排序, limit n 将仅返回第一个 n 记录。