Login | Register
“What is the highest item number?”
SELECT MAX(article) AS article FROM shop; +---------+ | article | +---------+ | 4 | +---------+
Similarly MIN can be used to find minium valueSELECT MIN(jnr_id) AS jnr_id FROM chain
+----------+| jnr_id |+----------+| 1000 |+----------+
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 outputtedExample:SELECT avg(article) AS article_avg FROM shop;
+-------------+| article_avg |+-------------+| 2.4286 |+-------------+
Also, you can use sum:mysql> select sum(article) as Total from shop;
+-------+| Total |+-------+| 17 | +-------+
How to display 4th highest (salary) record from customer table:mysql> SELECT sal FROM `emp` order by sal desc limit 3,1
Add your own comment.
User Comments
Similarly MIN can be used to find minium value
SELECT MIN(jnr_id) AS jnr_id FROM chain
You can use just about any function in a select query.
1 row in set (0.00 sec)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
Example:
SELECT avg(article) AS article_avg FROM shop;
Also, you can use sum:
mysql> select sum(article) as Total from shop;
How to display 4th highest (salary) record from customer table:
mysql> SELECT sal FROM `emp` order by sal desc limit 3,1
Add your own comment.