Documentation Home
MySQL 5.6 リファレンスマニュアル
Download this Manual
PDF (US Ltr) - 26.8Mb
PDF (A4) - 26.9Mb
HTML Download (TGZ) - 7.1Mb
HTML Download (Zip) - 7.2Mb

3.6.1 カラムの最大値


SELECT MAX(article) AS article FROM shop;

| article |
|       4 |

User Comments
  Posted by Najeem M Illyas on November 13, 2004
Similarly MIN can be used to find minium value

SELECT MIN(jnr_id) AS jnr_id FROM chain

| jnr_id |
| 1000 |
  Posted by Andy Pieters on February 6, 2005
You can use just about any function in a select query.

Besides the MAX, and MIN functions, there is also the AVG function to quickly calculate the Average value of a field.

* The AS parameter sets the name of the field that is outputted


SELECT avg(article) AS article_avg FROM shop;

| article_avg |
| 2.4286 |
1 row in set (0.00 sec)

  Posted by Alex Grim on December 13, 2006
Also, you can use sum:

mysql> select sum(article) as Total from shop;
| Total |
| 17 |

  Posted by Sony George on February 18, 2010
How to display 4th highest (salary) record from customer table:

mysql> SELECT sal FROM `emp` order by sal desc limit 3,1
  Posted by Kobus Myburgh on November 5, 2013
I can not find anything confirming this, but my tests indicate that if you use MAX() on a field with an alpha-numeric value (such as ETA-000001), it does calculate the MAX() correctly, providing the number is padded by 0's.

To get a better (and probably more syntactically correct) result, you could use the following:

MAX(SUBSTRING(reference_number FROM 5 FOR 6))

for the example number given above.
Sign Up Login You must be logged in to post a comment.