Post midterm SQL Flashcards
(36 cards)
How are alias that include whitespace referenced outside of the SELECT statement?
in brackets: [alias name].
DATEDIFF arguments in order:
DATEDIFF(1,2,3)
1: time metric.
2: date1, subtracted from date2
3: date2.
What is the use and data type output from MONTH(), YEAR(), or DAY()?
Use: isolate a time metric in a date data type.
Output: integer.
What is the Syntax for OFFSET & FETCH?
OFFSET ?? ROWS
FETCH NEXT ?? ROWS ONLY;
How do you filter for NULL or NON NULL values in the WHERE clause (Syntax)?
“attribute IS NULL” or “attribute IS NOT NULL.”
The 5 aggregate functions can be sorted into two categories based on output. What are they and what are their possible outputs?
COUNT(), AVG(), and SUM() create numeric outputs. They can be decimal or integer.
MIN() and MAX() can have string, numeric, or date outputs.
What two ways can you use COUNT() to find the number of rows in a table?
COUNT(PK_attribute) or COUNT(*).
What does DISTINCT do?
Selects unique values from the first attribute in the SELECT statement.
What stipulate does the use of GROUP BY put on the SELECT statement?
All SELECT statement attributes must be either in the GROUP BY clause or an aggregate function.
You can assign DESC order to each attribute in ORDER BY clause. True or False?
True.
Alphabetical Ascending
A to Z.
Alphabetical Descending
Z to A.
Date Ascending
Oldest date to newest date.
2003 to 2024.
Date Descending
Newest date to oldest date.
2024 to 2003.
CONCAT(IDNum, State) is ordered as a number because the values start with integers. True or false?
False. They are treated as alphanumeric values.
How is OVER(PARTITION BY …) used? What a syntax example?
Used with an aggregate to display the aggregate alongside each record of certain groups. It appears in the SELECT statement.
Ex: “AVG(Salary) OVER(PARTITION BY Gender).”
What does COUNT(*) OVER() do in the SELECT statement?
Returns total number of rows which is displayed with each row retrieved.
What is the syntax for a CASE column in the SELECT statement?
CASE
WHEN (…) THEN ‘value’
WHEN (…) THEN ‘value’
ELSE ‘value’
END AS ‘Alias’
Components in a CASE column in the SELECT statement?
CASE, WHEN, THEN, ELSE, & END.
ALTER is DML and UPDATE is DDL. True of False?
ALTER is data definition language and UPDATE is data manipulation language.
You cannot use CASE within UPDATE. It must be UPDATE SET WHERE. True of False?
False.
How do you use ALL or ANY?
They are used in non-correlated subqueries to get the compare the MAX() or MIN() of the inner query respectively. They go right before the inner query.
Ex: “WHERE Salary > ANY (…);”
How do you hardcode record labels (SYNTAX)?
“SELECT ‘string’ AS ‘ ‘ …”
There must be one whitespace in the alias.
ERROR_NUMBER()
Returns the error number when an error is caught, part of the Catch in a procedure.