The last reply time of the query article

Table: id, title, postuser, postdate, parentid
                  Prepare sql statement:
                  drop table if exists articles;
                  create table articles(id int auto_increment primary key, title
                  varchar(50), postuser varchar(10), postdate datetime, parentid
                  int references articles (id));
                  insert into articles values
                  ​​(null,'The first article','Zhang San','1998-10-10 12:32:32',null),
                  (null,'The second article','Zhang Three','1998-10-10 12:34:32',null),
                  (null,'The first reply 1','Li Si','1998-10-10 12:35:32',1) ,
                  (null,'The second reply 1','Li Si','1998-10-10 12:36:32',2),
                  (null,'The first reply 2','Wang Wu','1998-10-10 12:37:32',1),
                  (null,'The first reply 3','Li Si','1998-10-10 12:38:32',1),
                  (null,'The second reply 2','Li Si','1998 -10-10 12:39:32',2),
                  (null,'The first reply 4','Wang Wu','1998-10-10 12:39:40',1);
                  Answer:
                  select a .title,a.postuser,(select max(postdate) from articles where parentid=a.id) reply from articles a where a.parentid is null;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324780104&siteId=291194637