CS401A's Finals: Info Management Module 08 Flashcards
For final exams. (67 cards)
SQL Functions
performs a calculation on a set of values and returns a single value.
- An aggregate function
SQL Functions
- The basic aggregate functions are the following:
○ MIN
○ MAX
○ COUNT
○ SUM
○ AVG
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
— the minimum attribute value encountered in a given column
aggregate functions
○ MIN
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
— the maximum attribute value encountered in a given column
aggregate functions
○ MAX
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
— the number of rows containing non-null values
aggregate functions
○ COUNT
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
— the sum of all values for a given column
aggregate functions
○ SUM
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
— the arithmetic mean (average) for a specified column
aggregate functions
○ AVG
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
Table 2. Orders
Amount 130.50 297.50 794.25 332.75
-
\_\_\_\_\_
○ Example: SELECT\_\_\_\_\_
(Amount) FROM Orders;
○ Result: 130.50
- The basic aggregate functions are the following:
Table 2. Orders
Amount 130.50 297.50 794.25 332.75
-
MIN
○ Example: SELECT MIN(Amount) FROM Orders;
○ Result:\_\_\_\_\_\_\_
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
Table 2. Orders
Amount 130.50 297.50 794.25 332.75
-
\_\_\_\_\_
○ Example: SELECT\_\_\_\_\_
(Amount) FROM Orders;
○ Result: 794.25
- The basic aggregate functions are the following:
Table 2. Orders
Amount 130.50 297.50 794.25 332.75
-
MAX
○ Example: SELECT MAX(Amount) FROM Orders;
○ Result:\_\_\_\_\_\_\_
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
Table 2. Orders
OrderID 1 2 3 4
-
\_\_\_\_\_
○ Example 1: SELECT\_\_\_\_\_
(OrderID) FROM Orders;
○ Result: 4
- The basic aggregate functions are the following:
Table 2. Orders
OrderID 1 2 3 4
-
COUNT
○ Example 1: SELECT COUNT(OrderID) FROM Orders;
○ Result:\_\_
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
Table 2. Orders
OrderID | Amount 1 | 130.50 2 | 297.50 3 | 794.25 4 | 332.75
○ Example 2: SELECT \_\_\_\_\_
(OrderID) FROM Orders WHERE Amount > 300;
○ Result: 2
- The basic aggregate functions are the following:
Table 2. Orders
OrderID | Amount 1 | 130.50 2 | 297.50 3 | 794.25 4 | 332.75
-
COUNT
○ Example 2: SELECT COUNT(OrderID) FROM Orders WHERE Amount > 300;
○ Result:\_\_\_
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
Table 2. Orders
Amount 130.50 297.50 794.25 332.75
-
\_\_\_\_\_
○ Example: SELECT\_\_\_\_\_
(Amount) FROM Orders;
○ Result: 1555
- The basic aggregate functions are the following:
Table 2. Orders
~~~
Amount
130.50
297.50
794.25
332.75
```
* SUM
○ Example: SELECT SUM(Amount) FROM Orders;
○ Result: \_\_\_\_\_\_\_
SQL Functions
- The basic
\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are the following:
Table 2. Orders
Amount 130.50 297.50 794.25 332.75
-
\_\_\_\_\_
○ Example: SELECT\_\_\_\_\_
(Amount) FROM Orders;
○ Result: 388.75
- The basic aggregate functions are the following:
Table 2. Orders
Amount 130.50 297.50 794.25 332.75
-
AVG
○ Example: SELECT AVG(Amount) FROM Orders;
○ Result:\_\_\_\_\_\_\_\_\_
SQL Functions
is often used with aggregate functions to \_\_\_\_\_\_\_\_
the result-set by one or more columns
- The GROUP BY command option
SQL Functions
Table 2. Orders
OrderID | OrderDate 1 | 2020-02-14 2 | 2020-02-14 3 | 2020-02-14 4 | 2020-02-15
-
\_\_\_\_\_ \_\_
command option…
○ Example: SELECT OrderDate, COUNT(OrderID) FROM Orders\_\_\_\_\_ \_\_
OrderDate;
○ Result:
OrderDate | (No column name) 2020-02-14 | 3 2020-02-15 | 1
Table 2. Orders
OrderID | OrderDate 1 | 2020-02-14 2 | 2020-02-14 3 | 2020-02-14 4 | 2020-02-15
-
GROUP BY command option…
○ Example: SELECT OrderDate, COUNT(OrderID) FROM Orders GROUP BY OrderDate;
○ Result:
SQL Functions
to assign a temporary name to the column. It can also be given to tables.
-
GROUP BY command option…
Use an alias to
SQL Functions
Table 2. Orders
OrderID | OrderDate 1 | 2020-02-14 2 | 2020-02-14 3 | 2020-02-14 4 | 2020-02-15
-
\_\_\_\_\_ \_\_
command option\_\_\_\_\_
○ Example: SELECT OrderDate, COUNT(OrderID)\_\_
Quantity FROM Orders\_\_\_\_\_ \_\_
OrderDate;
○ Result:
OrderDate | Quantity 2020-02-14 | 3 2020-02-15 | 1
Table 2. Orders
OrderID | OrderDate 1 | 2020-02-14 2 | 2020-02-14 3 | 2020-02-14 4 | 2020-02-15
-
GROUP BY command option
alias
○ Example: SELECT OrderDate, COUNT(OrderID) AS Quantity FROM Orders GROUP BY OrderDate;
○ Result:
SQL Functions
is used to restrict the output of a GROUP BY query by applying conditional criteria to the grouped rows.
- The HAVING command option
SQL Functions
Table 2. Orders
OrderID | OrderDate 1 | 2020-02-14 2 | 2020-02-14 3 | 2020-02-14 4 | 2020-02-15
- The
\_\_\_\_\_\_
command option\_\_\_\_\_
○ Example: SELECT OrderDate, COUNT(OrderID)\_\_
Quantity FROM Orders\_\_\_\_\_ \_\_
OrderDate\_\_\_\_\_\_
Quantity > 2;
○ Result:
OrderDate | Quantity 2020-02-14 | 3
Table 2. Orders
OrderID | OrderDate 1 | 2020-02-14 2 | 2020-02-14 3 | 2020-02-14 4 | 2020-02-15
- The HAVING command option
alias
○ Example: SELECT OrderDate, COUNT(OrderID) AS Quantity FROM Orders GROUP BY OrderDate HAVING Quantity > 2;
○ Result:
SQL Functions
- The most commonly used date functions are as follows:
- The most commonly used
\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are as follows:
○ YEAR
○ MONTH
○ DAY
○ GETDATE
○ DATEADD
○ DATEDIFF
SQL Functions
- The most commonly used
\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are as follows:
— returns a four-digit\_\_\_\_
- The most commonly used date functions are as follows:
○ YEAR —
SQL Functions
- The most commonly used
\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are as follows:
— returns the number of the month
- The most commonly used date functions are as follows:
○ MONTH
SQL Functions
- The most commonly used
\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are as follows:
— returns the number of the day
- The most commonly used date functions are as follows:
○ DAY
SQL Functions
Table 2. Orders
OrderID | OrderDate 1 | 2020-02-14 2 | 2020-02-14 3 | 2020-02-14 4 | 2020-02-15
- The most commonly used
\_\_\_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
are as follows:
○\_\_\_\_\_\_\_\_
○\_\_\_\_\_\_\_\_
○\_\_\_\_\_\_\_\_
Example: SELECT OrderID,\_\_\_\_\_\_\_\_
(OrderDate) AS Year,\_\_\_\_\_\_\_\_
(OrderDate) AS Month,\_\_\_\_\_\_\_\_
(OrderDate) AS Day FROM Orders;
Result of query:
OrderID | Year | Month | Day 1 | 2020 | 2 | 14 2 | 2020 | 2 | 14 3 | 2020 | 2 | 14 4 | 2020 | 2 | 15
Table 2. Orders
OrderID | OrderDate 1 | 2020-02-14 2 | 2020-02-14 3 | 2020-02-14 4 | 2020-02-15
- The most commonly used date functions are as follows:
○ YEAR
○ MONTH
○ DAY
Example: SELECT OrderID, YEAR(OrderDate) AS Year, MONTH(OrderDate) AS Month, DAY(OrderDate) AS Day FROM Orders;
Result of query: