Mysql query maximum value statement is: first group stuname field; then use MAX function to calculate the maximum value in each group, the code is [SELECT a.stuname,MAX(a. score) AS..].
【Related learning recommendation: mysql tutorial(video)】
Mysql query maximum value statement is:
1, method 1
SELECT a.stuname,MAX(a.score) AS score FROM stuscore a GROUP BY a.`stuname` ;
In this statement, we group by stuname field and then use MAX() The function calculates the maximum value in each group.
2. Method 2: use connection
SELECT a.stuname,a.score AS score FROM stuscore a JOIN stuscore b ON a.`stuname`=b.`stuname` GROUP BY a.`score` HAVING a.`score`=MAX(b.`score`);
In the second sql statement, we use stuname as the judgment condition to perform two table Connection operation. If only execute
SELECT a.stuname,a.score AS score FROM stuscore a JOIN
stuscore b ON a. stuname=b.stuname
We will get the following result set:
The above is the detailed content of the mysql query maximum value statement, more Please pay attention to other related articles on 1024programmer.com!