1024programmer Mysql What is the maximum value statement of mysql query

What is the maximum value statement of mysql query

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!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/what-is-the-maximum-value-statement-of-mysql-query/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索