SQL P1 Flashcards
part 1 of studying
Window Syntax
WDFn() over (partition by [col] order by [col]) as new_col_name
WDFn: RANK()
same # => same Rank
leaves gaps after repeated ranks
nulls given same rank
WDFn: DENSE_RANK()
same # => same Rank
no gap after repeated rank
WDFn:ROW_NUMBER()
just a # to each tow. no repeated ranks
PERCENT_RANK()
ordered % of data
UNION
UNION combines the results of two result sets and removes duplicates. UNION ALL doesn’t remove duplicate rows.
INTERSECT
INTERSECT returns only rows that appear in both result sets.
EXCEPT
EXCEPT returns only the rows that appear in the first result set but do not appear in the second result set.
ROWS BETWEEN lower_bound AND upper_bound
just remember it
UNBOUNDED PRECEDING
All rows before the current row.
n PRECEDING
n rows before the current row.
CURRENT ROW
Just the current row.
n FOLLOWING
n rows after the current row.
UNBOUNDED FOLLOWING
All rows after the current row.