Like most other RDBMSs, SQL Server has an AVG()
function that returns the average of the values in a group.
Below are examples that demonstrate how the AVG()
function works in SQL Server.
Like most other RDBMSs, SQL Server has an AVG()
function that returns the average of the values in a group.
Below are examples that demonstrate how the AVG()
function works in SQL Server.
In SQL Server, the GREATEST()
function returns the maximum value from a list of one or more expressions.
The GREATEST()
function was introduced in SQL Server 2022 (along with the LEAST()
function).
SQL Server 2022 introduced the LEAST()
and GREATEST()
functions, which allow us to get the minimum or maximum value from a list of expressions.
The LEAST()
function returns the minimum value from a list of one or more expressions.
Most major RDBMSs support the DISTINCT
clause, which allows us to get unique – or “distinct” – rows from our SQL queries. But PostgreSQL’s implementation of this clause has an extra option that most other RDBMSs don’t include.
PostgreSQL allows us to include the ON()
option when using DISTINCT
. This enables us to specify exactly which columns should be evaluated by the DISTINCT
modifier, while simultaneously allowing us to return columns that aren’t evaluated.
Many SQL databases have a window function called NTILE()
function that divides a rowset or partition into a given number of groups (buckets). The function typically returns the bucket number of the current row within its partition.
Most of the major relational database management systems (RDBMSs) allow for a DISTINCT
clause to be included in our SQL queries.
We use the DISTINCT
keyword to return only unique rows. It eliminates duplicates from the results. If we have two or more rows with exactly the same data, we’ll only see one row in the results.
In Oracle Database, we can use the OFFSET
clause to make a SELECT
statement skip a certain number of rows in its result set.
The OFFSET
clause is defined as part of the FETCH
row limiting clause, which allows us to limit the number of rows returned by a query.
We can therefore use both OFFSET
and FETCH
to limit the output to just the specified number or percentage of rows, at a specified offset.
The LAG()
function is a window function that’s available in many SQL databases. It returns the value of a given expression from the row that lags (precedes) the current row by a given number of rows within its partition.
In other words, the LAG()
function returns a value from a previous row.
Many relational database management systems (RDBMSs) have a LEAD()
function that allows us to retrieve a value from a following row.
The SQL LEAD()
function returns the value of a given expression from the row that leads (follows) the current row by a given number of rows within its partition.
Some of the major relational database management systems (RDBMSs) have a LIMIT
clause that enables us to reduce the number of rows returned by a query.
The way it works is that we provide the number of rows we want to be returned by the query. We can also provide an offset to specify which row to start the count from.
Continue reading