/*先并表再筛选最近日期相关信息,较为复杂;可以先筛选最大日期信息,再并表。
1、
with t as(
    select *
    from login
    where id in(select id from login               --无法精确对应到将每个user_id的maxdate,提交报错
                where date in (select max(date) from login 
                            group by user_id))
)
select u.name u_n,
    c.name c_n,
    date
from t
left join user u on t.user_id=u.id
left join client c on t.client_id=c.id
order by u_n
2、
with max_date as(
    select user_id,max(date) maxdate
    from login
    group by user_id
)

select u.name u_n,
    c.name c_n,
    date
from login a
left join max_date using(user_id)
left join user u on a.user_id=u.id
left join client c on a.client_id=c.id
where date=maxdate
order by u_n
3、*/
with t as(
    select *
    from login
    where (user_id,date) in (select user_id,max(date) from login group by user_id)
)
select u.name u_n,
    c.name c_n,
    date
from t
left join user u on t.user_id=u.id
left join client c on t.client_id=c.id
order by u_n




where (column1,column2,...) in 子查询/tablename