基于 user_id 分组但不使用连接和子查询

Group by based on user_id but without using join and sub query

如何在不使用连接和子查询的情况下基于user_id按此场景进行分组,结果我需要最新的日期。

user_id    name            date
1          mike           14-12-2015
2          bob            14-12-2015
1          Thomas         15-12-2015
2          john           15-12-2015

输出应该是数据库中存储的最新数据。

select user_id, max(date)
from your_table
group by user_id

试试这个查询:-

select *
from table t1 
where date=(SELECT MAX(t2.date)
              FROM table t2
              WHERE t1.user_id = t2.user_id)