Home > database >  Write a SQL to SQL bosses to help
Write a SQL to SQL bosses to help

Time:04-12




The same user query the latest records every day
For example:
Field (user id) field b (create time)
A 2021-04-11 12:54:56
The 2021-04-11 b 10:12:21
A 2021-04-11 02:25:36
The 2021-04-11 b 18:44:24
A 2021-04-06 12:20:10
The 2021-04-08 b 08:05:47
A 2021-04-07 15:25:36


Expected results:
A 2021-04-11 12:54:56
The 2021-04-11 b 18:44:24
A 2021-04-06 12:20:10
The 2021-04-08 b 08:05:47
A 2021-04-07 15:25:36

CodePudding user response:

Select * from (select DISTINCT * from table name ORDER BY CJSJ desc) temp GROUP BY temp. The uid, convert (temp. CJSJ, CHAR (10)) ORDER BY CJSJ desc

CodePudding user response:

 
Select a, Max (b) from the name of the table GROUP BY a, the DATE (b)
  • Related