MySQL-MySQL group query for the latest piece of data in each group

method one:

1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'se_jck++'s Blog-CSDN Blog

This error is due to the default mode enabled in the new version of MySQL ONLY_FULL_GROUP_BY, that is, in the GROUP BY

The SELECT list in the statement can only contain grouping or aggregation functions , and cannot contain other columns. 

Method Two:

Obtain the latest time and address through the MAX function (because it needs to be grouped by address), and then use it as a table and the original data

To perform a joint search, the condition is that the address and time must be equal to the maximum time and address obtained.

reference:

Query the latest data after MySql grouping_mysql grouping latest data_Dadyage's Blog-CSDN Blog

https://www.cnblogs.com/java-spring/p/11498457.html

MySQL group query for the latest piece of data in each group (easy to understand) - Programmer Sought

Guess you like

Origin blog.csdn.net/ZHOU_VIP/article/details/131640160