牛客每天有很多人登录,请你统计一下牛客每个用户最近登录是哪一天。 有一个登录(login)记录表,简况如下: id user_id client_id date 1 2 3 4 2 3 2 3 1 2 2 2 2020-10-12 2020-10-12 2020-10-13 2020-10-13 第1行表示user_id为2的用户在2020-10-12使用了客户端id为1的设备登录了牛客网 。。。 第4行表示user_id为3的用户在2020-10-13使用了客户端id为2的设备登录了牛客网 请你写出一个sql语句查询每个用户最近一天登录的日子,并且按照user_id升序排序,上面的例子查询结果如下: user_id id 2 3 2020-10-13 2020-10-13 查询结果表明: user_id为2的最近的登录日期在2020-10-13 user_id为3的最近的登录日期也是2020-10-13
示例1

输入

drop table if exists login;
drop table if exists user;
drop table if exists client;
CREATE TABLE login (
id int(4) NOT NULL,
user_id int(4) NOT NULL,
client_id int(4) NOT NULL,
date date NOT NULL,
PRIMARY KEY (id));

CREATE TABLE user (
id int(4) NOT NULL,
name varchar(32) NOT NULL,
PRIMARY KEY (id));

CREATE TABLE client (
id int(4) NOT NULL,
name varchar(32) NOT NULL,
PRIMARY KEY (id));

INSERT INTO login VALUES
(1,2,1,'2020-10-12'),
(2,3,2,'2020-10-12'),
(3,2,2,'2020-10-13'),
(4,3,2,'2020-10-13');

INSERT INTO user VALUES
(1,'tm'),
(2,'fh'),
(3,'wangchao');

INSERT INTO client VALUES
(1,'pc'),
(2,'ios'),
(3,'anroid'),
(4,'h5');

输出

2|2020-10-13
3|2020-10-13
加载中...