dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Selecting the Max, Min and Sum of Values from a Table in MySQL

Learn how to find the max, min and sum of values from a column in a table in MySQL.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Considering the following table STOCKPRICE and its details.

CREATE TABLE 'STOCKPRICE' (
'ID' INT(11) NOT NULL,
'NAME' TEXT NOT NULL COLLATE 'utf8_bin',
'PRICE' INT(11) NOT NULL
)
COLLATE='utf8_bin'
ENGINE=InnoDB
;

Also, use the following to create sample data as below.

INSERT INTO 'STOCKPRICE' ('ID', 'NAME', 'PRICE') VALUES (1, 'ABC Ltd', 15);
INSERT INTO 'STOCKPRICE' ('ID', 'NAME', 'PRICE') VALUES (2, 'XYZ Ltd', 19);
INSERT INTO 'STOCKPRICE' ('ID', 'NAME', 'PRICE') VALUES (3, 'AAA Ltd', 16);

Now, you can find out the maximum, minimum values and sum of values in the PRICE column using the queries below:

For Max value -- SELECT MAX(PRICE) MAXPRICE FROM STOCKPRICE
For Min value -- SELECT MIN(PRICE) MINPRICE FROM STOCKPRICE
For SUM of all values -- SELECT SUM(PRICE) SUMPRICE FROM STOCKPRICE

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date