Live Lecure Materials Week 11 Flashcards
(20 cards)
You can sort results using the
ORDER BY clause
You can sort in __________ (___) or __________ (____) order
Ascending (ASC) or descending (DSC)
Count(*), COUNT({Name}), SUM, AVG, MIN, MAX are examples of
Aggregate functions
Count(*)
Counts the number of rows in a table
Count({Name})
Counts rows where the column name is not null
Min
Calculates the minimum value of all values
Max
Calculates the maximum of all values
Aggregate functions allow you to view a ______ piece of data from ________ pieces of data
single, multiple
Most normal functions operate on a ______ ___, most aggregate functions operate on ________ ____
single row, multiple rows
Put these in order for a SUM function
Sum( OrderTotal )
FROM
AS OrderSum
RETAIL_ORDER
SELECT
SELECT SUM( OrderTotal ) AS OrderSum FROM RETAIL_ORDER
Clause that specifies which rows will be used to determine the groups
WHERE
Clause that specifies which groups will be used in the final result
HAVING
T/F - The WHERE clause should be placed before the GROUP BY clause
True
T/F - HAVING applies before WHERE
False
T/F - Rows can be grouped by more than one column
True
Groups rows that have the same values into summary rows
GROUP BY
If there is a column in the SELECT clause that is not used by any other functions in a statement, it must
be used in the group by clause. Otherwise the query will return an error.
1 of the 2 limits to built-in aggregate functions
You cannot combine table column names with aggregate functions
2 of the 2 limits to SQL built in functions
You cannot use aggregate functions in the WHERE clause
SELECT OrderNumber, SKU
FROM ORDER_ITEM
WHERE (Quantity * Price) <> ExtendedPrice
ORDER BY OrderNumber, SKU;
This returns no results, why?
There are no rows where Quantity * Price does not equal ExtendedPrice. It is working correctly.