我在表格中有日期:
2018-09-01 02:22:23
2018-09-01 02:22:25
2018-09-01 02:22:28
2018-09-02 02:22:22
2018-09-02 02:30:00
SELECT * FROM table_name where columnA = order by 1 desc;
columnA是TIMESTAMP
我希望从当天返回最长日期。有谁知道这个查询应该是什么样的?
答案 0 :(得分:2)
查询应该看起来像 -
以下是特定日期 -
select max(columnA) from table_name
where trunc(columnA) = date 'yyyy-mm-dd' ;-- this is for oracle
-- where date(columnA) = 'yyyy-mm-dd' ;-- this is for mysql
如果您要求它是通用的,那么解决方案也可以是,以便为每天提供最大时间戳 -
select max(A.columnA) from table_name A
group by trunc(A.columnA); -- this is for oracle
-- group by date(A.columnA); -- this is for mysql
答案 1 :(得分:1)
尝试此查询
SELECT columnA FROM table_name WHERE where trunc(columnA ) = to_date('2018-09-02', 'YYYY-MM-DD') order by columnA DESC LIMIT 1
答案 2 :(得分:0)
您可以使用order by desc
和limit
SELECT * FROM table
ORDER BY date_field DESC
LIMIT 1;