SQL Function 1
SQL Function 1
SQL Function 1
Tip: The aggregate functions and the scalar functions will be explained in details in the next
chapters.
Demo Database_AVG()
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Products" table:
ProductI
D
ProductName
SupplierI CategoryI
D
D
Unit
Price
Chais
10 boxes x 20 bags 18
Chang
24 - 12 oz bottles
Aniseed Syrup
12 - 550 ml bottles 10
48 - 6 oz jars
21.35
36 boxes
25
19
The following SQL statement selects the "ProductName" and "Price" records that have an
above average price:
Demo Database_Count()
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Orders" table:
OrderID
CustomerID
EmployeeID
OrderDate
ShipperID
10265
1996-07-25
10266
87
1996-07-26
10267
25
1996-07-29
The following SQL statement counts the total number of orders in the "Orders"
table:
SELECT COUNT(*) AS NumberOfOrders FROM Orders;
The following SQL statement counts the number of unique customers in the
"Orders" table:
Demo Database_First()
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Customers" table:
Custom
erID
CustomerName
ContactNa
me
Address
City
PostalC Count
ode
ry
12209
Germa
ny
Ana Trujillo
Avda. de la
Mxico
05021
Constitucin 2222 D.F.
Mexico
Antonio Moreno
Taquera
Antonio
Moreno
Mataderos 2312
Mxico
05023
D.F.
Mexico
Thomas
Hardy
Berglunds snabbkp
Christina
Berglund
Berguvsvgen 8
Lule
Alfreds Futterkiste
Ana Trujillo
Emparedados y
helados
Berlin
S-958 22
Swede
n
Demo Database_Last()
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Customers" table:
Custom
erID
CustomerName
ContactNa
me
Address
City
PostalC Count
ode
ry
12209
Germa
ny
Ana Trujillo
Avda. de la
Mxico
05021
Constitucin 2222 D.F.
Mexico
Antonio Moreno
Taquera
Antonio
Moreno
Mataderos 2312
Mxico
05023
D.F.
Mexico
Thomas
Hardy
Berglunds snabbkp
Christina
Berglund
Berguvsvgen 8
Lule
Alfreds Futterkiste
Ana Trujillo
Emparedados y
helados
Berlin
S-958 22
Swede
n
The following SQL statement selects the last value of the "CustomerName"
column from the "Customers" table:
SELECT LAST(CustomerName) AS LastCustomer FROM Customers;
Demo Database_MAX()
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Products" table:
ProductI
D
ProductName
SupplierI CategoryI
D
D
Unit
Price
Chais
10 boxes x 20 bags 18
Chang
24 - 12 oz bottles
Aniseed Syrup
12 - 550 ml bottles 10
48 - 6 oz jars
21.35
36 boxes
25
19
Demo Database_MIN()
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Products" table:
ProductI
D
ProductName
SupplierI CategoryI
D
D
Unit
Price
Chais
10 boxes x 20 bags 18
Chang
24 - 12 oz bottles
Aniseed Syrup
12 - 550 ml bottles 10
48 - 6 oz jars
21.35
36 boxes
25
19
Demo Database_SUM()
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "OrderDetails" table:
OrderDetailID
OrderID
ProductID
Quantity
10248
11
12
10248
42
10
10248
72
10249
14
10249
51
40