Latest web development tutorials

SQL Functions

SQL has a lot of built-in functions can be used for counting and calculations.


SQL Aggregate Functions

SQL Aggregate functions calculate the value obtained from the column to return a single value.

Useful Aggregate Functions:

  • AVG () - Returns the average
  • COUNT () - Returns the number of rows
  • Returns the value of the first record - FIRST ()
  • LAST () - Returns the value of the last record
  • MAX () - Returns the maximum value
  • MIN () - Returns the minimum value
  • SUM () - Returns the total

SQL Scalar Functions

SQL Scalar functions based on the input value and return a single value.

Useful Scalar Functions:

  • UCASE () - a field will be converted to uppercase
  • LCASE () - a field will be converted to lowercase
  • MID () - extract characters from a text field
  • LEN () - Returns the length of a text field
  • ROUND () - for a specified number of decimal places a numeric field rounding
  • NOW () - Returns the current system date and time
  • Display format of a field - FORMAT ()

Note: In the following sections, we will explain in detail the function Aggregate and Scalar Functions.