Kee*_*thi 1 mysql query-optimization database-performance groupwise-maximum
我正在尝试从 SQL 表中检索每条记录的最新数据。每条记录都会有重复的数据,并有一些数据变化。我需要检索最新的带时间戳的数据。有人可以建议哪个是性能方面的最佳解决方案吗?见过一些带有内部联接和子查询的解决方案。
下面给出的示例数据
Technology Students Amount Area Date
python 500 1000 Bangalore 2021-08-06 12:03:26
Ruby 100 1000 Bangalore 2021-08-06 05:18:50
Java 300 1000 Bangalore 2021-08-06 18:23:40
python 900 1000 Bangalore 2021-08-06 16:23:30
Java 100 1000 Bangalore 2021-08-06 12:23:50
Ruby 500 1000 Bangalore 2021-08-06 15:13:40
Run Code Online (Sandbox Code Playgroud)
我的 O/P 应该包含每种技术的最新数据
Technology Students Amount Area Date
Java 300 1000 Bangalore 2021-08-06 18:23:40
python 900 1000 Bangalore 2021-08-06 16:23:30
Ruby 500 1000 Bangalore 2021-08-06 15:13:40
Run Code Online (Sandbox Code Playgroud)
小智 5
一种方法是:- *将表替换为真实的表名称。
select table.*
from table
join
(
select Technology, max(Date) as max_dt
from table
group by Technology
) t
on table.Technology= t.Technology and table.Date = t.max_dt
Run Code Online (Sandbox Code Playgroud)