How to use the SUM function in MySQL
MySQL provides a number of aggregate functions for quickly compiling the data in your tables. These added features work inside the SELECT queries, and their results, especially the return columns. The aggregate functions are fast - much faster than it would be to return all the rows and calculate yourself. This can mean the difference between a 2-second consultation with the aggregate function and a 2-minute consultation by making the calculation in itself, the application code .
Use the SUM function in MySQL
Use the SUM aggregate function. Sum added all the columns together .
Notice how, in this example, you sum all negative balances to calculate the total amount owed to it by its customers. The result returns in a column called SUM (balance). Example: SELECT SUM (balance) from customers when balance <0.0 ;
Use the AVG in MySQL
Use the overall role of AVG. This is similar to SUM added. However, instead of adding columns, and then adds divided by the total number of columns, giving an average of the values in column of YLG .
use the same manner used SUM. In this sense, the example calculates the average amount of money owed by customers. Results back in a column called AVG (balance). Example: SELECT AVG (balance) from customers when balance <0.0 ;
Use the COUNT function in MySQL
Use the aggregate COUNT. This function is slightly different than the sum or AVG. It returns the number of rows returned, which can be useful in a variety of situations - for example, to see the number of customers who owe money .
See how this example account customers who owe money and returns the result in a column called COUNT (*). Example: select count (*) FROM WHERE customers balance <0.0 ;
Use the DISTINCT COUNT in MySQL
Use the DISTINCT COUNT aggregate function. The function can be used to repay the number of rows within the meaning of the rows with different values. In theory, you could have a large number of customers with the same phone number. To get the number of households living their customers can use this type of consultation .
use the following example, to return the number of customers with different phone numbers. Customers with the same phone number will not be counted. The results are displayed in a column called COUNT (DISTINCT ph_number). Example: select count (DISTINCT ph_number) from customers;
Featured Links:
Proven Money Maker At $9,547 A Day.
Burn The Fat - Top Selling Fat Loss Ebook Since 2003.
Have You Ever Stayed Awake at Night Stressing About Whether or Not Your Marriage Will Last ... And What You Can Possibly Do to Save It?
Scan your computer for hidden AdWare and Spyware, Remove them permanently.
Join the Internet revolution and start downloading free movies and more!
Internet Marketer Gets $87 Million in Google Pay-Per-Click Ads FREE! ... And Makes Over $314 Million as a Result! ...And Now He's Going to Give You This Same Secret for Next to Nothing!








Leave a comment
You must be logged in to post a comment.