Built-in Database Functions
Aggregate Functions: These functions operate on a collection of values, such as all the values in a column, and return a single value or null. Examples include:
SUM(): Adds up all the values in a column.MIN(): Returns the lowest value.MAX(): Returns the highest value.AVG(): Returns the average or mean value.
Using Aggregate Functions:
- Aggregate functions are applied to columns by specifying the column name within parentheses after the function name.
- It's possible to explicitly name the resulting column using the
ASkeyword.
Scalar Functions: These functions operate on individual values and can perform operations like rounding, string manipulation, etc. Examples include:
ROUND(): Rounds values to the nearest integer.LENGTH(): Returns the length of a string.UPPERCASE(),LOWERCASE(): Convert strings to uppercase or lowercase.
Using Scalar Functions:
- Scalar functions are applied to individual values or columns in a similar manner to aggregate functions.
String Functions:
- A subset of scalar functions specifically designed for string manipulation.
- Useful for working with character and varchar values.
Using String Functions:
- Examples include functions like
LENGTH(),UPPERCASE(),LOWERCASE(). - These functions can be used in the
SELECTstatement to manipulate string values.
- Examples include functions like
Combining Functions:
- Functions can be nested, allowing one function to operate on the output of another function.
- For example,
UPPERCASE(ANIMAL)can be nested withinDISTINCTto get unique uppercase values from theANIMALcolumn.
Understanding and leveraging these built-in functions can greatly enhance the efficiency and effectiveness of SQL queries, allowing for complex data manipulation directly within the database. Thank you for watching!
Comments
Post a Comment