Windowing Flashcards

1
Q

What are SQL window functions?

A

SQL window functions compute values based on a set of rows related to the current row (called a window or window frame).
Examples include ROW_NUMBER(), SUM(), LEAD(), and NTILE().
The OVER() clause defines the window for these functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we find duplicates?

A

GROUP BY with COUNT() and HAVING COUNT() > 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why use windowing functions over subqueries?

A

Windowing functions provide similar results to subqueries but are more efficient.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do we order rows?

A

Use ORDER BY column_name to sort rows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is Rank ?

A

Use RANK() or DENSE_RANK() to assign ranks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ROW_NUMBER() ?

A

Returns the position of the row in the result set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

RANK()

A

Ranks rows based on a given value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

DENSE_RANK()

A

Ranks rows without leaving gaps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Analytic functions:

A

EAD(), LAG(), FIRST_VALUE(): Access data from other rows in the same window.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do we compare with previous/next rows?

A

Use LEAD() and LAG() to access adjacent row values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are these advanced grouping techniques?

A

GROUPING SETS, ROLLUP, and CUBE allow flexible aggregation.
They generate multiple levels of subtotals and grand totals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How Are Window Functions Configured?

A

Window functions use the OVER clause:

Window partition (PARTITION BY): Groups rows into partitions.
Window ordering (ORDER BY): Defines row order within each window.
Window frame (ROWS): Defines the window using offsets from a specified row.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly