The GROUP BY clause in Microsoft SQL Server is used to group rows with similar values in one or more columns into summary rows. It is essential for aggregating and summarizing data.
In Microsoft SQL Server, in-built functions provide a wide range of tools for manipulating and analyzing data. This chapter explores various categories of in-built functions and their real-world use cases.
String functions allow you to perform operations on text data.
SELECT
LEN('Hello, World!')
AS
Length;
SELECT CONCAT(
FirstName, ' ', LastName)
AS
FullName
FROM
Employees;
Numeric functions help with mathematical operations on numeric data.
● SUM(): Calculates the sum of numeric values in a column.
SELECT SUM
(Revenue)
AS
TotalRevenue
FROM
Sales;
● AVG(): Computes the average of numeric values in a column.
SELECT AVG
(Salary)
AS
AvgSalary
FROM
Employees;
● GETDATE(): Retrieves the current date and time.
SELECT
GETDATE()
AS
CurrentDateTime ;
● DATEDIFF(): Calculates the difference between two dates.
SELECT
DATEDIFF(DAY, OrderDate, ShippedDate)
AS
DaysToShip
FROM
Orders;
The GROUP BY clause in Microsoft SQL Server is used to group rows with similar values in one or more columns into summary rows. It is essential for aggregating and summarizing data.
In Microsoft SQL Server, User-Defined Functions (UDFs) are custom functions that allow you to encapsulate logic and perform specific tasks. This chapter explores the creation, usage, and real-world applications of UDFs.