Use the SELECT date - '2017-08-28' date, id from t_info WHERE cpName='Mars network and id!=44 this statement query out the result of such long
Then the query results as a list a, query the date for the maximum when the data
SELECT MAX (date), id from (SELECT date - '2017-08-28' date, id from t_info WHERE cpName='Mars network and id!=44) as a
This data is what the devil, the date and id not corresponding to the ah,,,
CodePudding user response:
So I think SQL have the following results are understandable:One, an error, because a field maximize, another field is not specified grouping function
Second, the kind of results you want
Three, date and all the id of the largest output, that is to say there are three data
Four, the output maximum date and query to the first id of
You can also consider the situation, if there are multiple biggest date, how to do?
Want to you of the result, actually can sort by date, with the result of the query and then using limit is limited only to remove
1Multiple results if there are multiple results is what you want, then can use the subquery removed first date, the largest and find out all the record date is equal to the largest date
CodePudding user response:
Max is right, as for the id, because not in the group by, so take the value of the record is li (the id is not in the group by strictly is the wrong behavior, just mysql support this behavior)If you want to take the biggest that record, it should be the order by the date desc limit 1
CodePudding user response:
Detailed information refer to the website documentationhttps://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html