MySQL GROUP BY
The GROUP BY statement in SQL is used to arrange data into groups with the help of some functions. GROUP BY statement is used to retrieve grouped records based on one or more columns.
The syntax for GROUP BY Statement in SQL -:
Description MySQL GROUP BY -:
GROUP BY(Nested Grouping) using more than one column -
Syntex -
GROUP BY Condition -
Syntex -
An aggregate function performs a calculation on multiple values and returns a single value.
1. MAX ()
MAX function returns the maximum value of an expression.
2. MIN ()
MIN function returns the minimum value of an expression.
3. AVG ()
AVG function returns the average value of an expression.
4. SUM ()
SUM function returns the summed value of an expression.
5. COUNT () and COUNT (*)
COUNT function returns the count of an expression.
For preforming the operations on dates, MySQL has provided some function:
1. NOW ()
NOW function returns the current date and time.
2. DATE ()
3. MONTH ()
MONTH function returns the month portion of a date value.
4. MONTHNAME ()
MONTHNAME function returns the full name of the month for a date.
5. YEAR ()
YEAR function returns the year portion of a date value.
6. DAY ()
DAY function returns the day portion of a date value.
7. DAYNAME ()
For preforming the operations on strings, MySQL has provided some function:
1. UCASE ()/UPPER ()
It converts all characters in the specified string to uppercase. If there are characters in the string that are not letters, they are unaffected by this function.
2. LCASE ()/LOWER ()
3. MID ()/SUBSTRING ()/SUBSTR ()
This function allows you to extract a substring from a string.
4. LENGTH ()
5. LEFT ()
LEFT function allows you to extract a substring from a string, starting from the left-most character.
6. RIGHT ()
The RIGHT function allows you to extract a substring from a string, starting from the right-most character.
7. INSTR ()
INSTR function returns the location of a substring in a string.
8. LTRIM ()
LTRIM function removes all space characters from the left-hand side of a string.
9. RTRIM ()
RTRIM function removes all space characters from the right-hand side of a string.
10. TRIM ()
TRIM function removes all specified characters either from the beginning or the end of a string.