Sabtu, 20 Agustus 2016

[Step 09] Learn to command the query "sum,min,max,avg, and count" in MySQL


In this post, we will teach you some new query commands. that is "sum,min,max,avg, and count".
previous reopen the database "items" that we have created in the previous post, if you do not have then you can read the previous post or make it like the screenshot below (ScreenShot: Database Becoding).
ScreenShot: Database Becoding [Click Here]
If the database is opened, we will continue our learning.

1.SUM
command "SUM" is used to calculate the overall amount of the data (summation), for example if we want to calculate the total price of all items.
then the command is: "select sum(price) from items;"
it will get results 10600000 (obtained from the calculation 1500000 + 4500000 + 1100000 + 3500000)

2.MIN
the "Min" is used to find the lowest value data of a data set. for example, we want to find the cheapest price of the item.
then the command is: "select min(price) from items;"
then we will get results 1100000 as the cheapest price. 
  
3.MAX
command "MAX" was the opposite of min. Because with this command, we can look for the highest value of a data set. for example, we want to find the price of the most expensive items.
then the command is: "select max(price) from items;"
then we will get results 4500000 as the price of the most expensive.

4.AVG
The "Avg" is the command to find the average value of a data set. For example, we want to find the average value of the item's price.
then the command is: "select avg(price) from items;"
it will get a result that is 2650000 (obtained from the (4500000 + 1500000 + 1100000 + 3500000) / 4).
 
5.COUNT
Command "cout" is a command to calculate the total amount of data in a table. For example, we want to know how much data item stored in the table "items".
then the command is: "select count(items_id) from items;"
it will get results of 4, because in the table "items" there are four pieces of data.
 

For more information you can see the screenshots below. 
ScreenShot: Process Query [Click Here] 

It was how to use the query "sum,min,max,avg, and count" in the mysql database. A few of our tutorial, we hope this article can help you all. And we thank you very much for your visit. 

Tidak ada komentar:

Posting Komentar