Group Functions Flashcards

1
Q

Which group functions will consider NULL values?

A

COUNT(*) and GROUPING

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

Can custom functions work on grouped data?

A

No

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

If no GROUP BY clause is specified, the default grouping becomes ____

A

The entire result set

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

What can be used as arguments for ORDER BY

A

the identifier or the column position (number)

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

AVG

A

AVG([{DISTINCT | ALL}] n) where n is a numeric expression to be evaluated.

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

COUNT

A

COUNT({* | [DISTINCT | ALL] })
If DISTINCT not specified, defaults to ALL
* counts all rows in result set, including NULL

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

MAX

A

MAX([{DISTINCT | ALL}] )
Can be datetime, numeric or character.
Character returns highest based on character set.

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

MIN

A

MIN([{DISTINCT | ALL}] )
Can be datetime, numeric or character.
Character returns highest based on character set.

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

SUM

A

SUM([{DISTINCT | ALL}] )

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

MEDIAN

A

MEDIAN() Returns middle value of result set.

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

STDDEV

A

STDDEV([{DISTINCT | ALL}] ) Returns standard deviation of result set.

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

VARIANCE

A

VARIANCE([{DISTINCT | ALL}] ) Returns numerical variance of result set.

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

LISTAGG

A

LISTAGG( [col_name, ‘, ‘]) WITHIN GROUP ( ORDER BY )

Aggregates data from multiple rows into one row per group.

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

CORR

A

CORR(y, x) Returns coefficient of the correlation of a set of number pairs.

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

COVAR_POP

A

COVAR_POP(y, x) Returns population covariance of a set of number pairs. Covariance can return NULL.

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

COVAR_SAMP

A

COVAR_SAMP(y, x) Returns the sample covariance of a set of number pairs. Covariance can return NULL.

17
Q

CUME_DIST

A

CUME_DIST() WITHIN GROUP (ORDER BY col_list [ASC|DESC] [NULLS {first|last}])
where val_list is a comma-delimited list of expressions that evaluate to numeric constants and col_list is the comma-delimited list of column expressions.
Returns the cumulative distribution of a value in val_list within a distribution in col_list.
Result will be between 0 and 1.

18
Q

DENSE_RANK

A

DENSE_RANK(val_list) WITHIN GROUP (ORDER BY col_list [ASC|DESC] [NULLS {first|last}])
where val_list is a comma-delimited list of expressions that evaluate to numeric constants and col_list is the comma-delimited list of column expressions.
Returns the row’s rank within an ordered group, which are consecutive integers starting with 1 reflecting the number of unique values returned by the query.

19
Q

GROUP_ID

A

GROUP_ID( )
No arguments
Requires GROUP BY
Returns a unique identifier for duplicate groups which is a value between 0 and i-1 where i is the number of duplicate groups.

20
Q

GROUPING

A

GROUPING(x) Applicable to statements with a ROLLUP or CUBE clause. Returns 1 for summary rows and 0 for nonsummary.

21
Q

PERCENT_RANK

A

PERCENT_RANK() WITHIN GROUP (ORDER BY col_list [ASC|DESC] [NULLS {first|last}])
Returns the percent ranking of a value in val_list within a distribution in col_list in the range between 0 and 1. Can return 0 whereas CUME_DIST cannot.

22
Q

PERCENTILE_CONT

A

PERCENTILE_CONT() WITHIN GROUP (ORDER BY col_list [ASC|DESC])
Assumes a continuous distribution and returns the interpolated value that would fall in percentile position x within the sorted group col_list.

23
Q

PERCENTILE_DISC

A

Same as PERCENTILE_CONT but assumes discrete distribution and will return the middle-most of the values in the list.

24
Q

RANK

A

RANK() WITHIN GROUP (ORDER BY col_list [ASC|DESC] [NULLS {first|last}])
Like DENSE_RANK but will include duplicate values.
If there are three values tied for first place, DENSE_RANK would just list one of them as first and ignore the next two, putting the fourth in 2nd place. RANK on the other hand will list them all as in 1st place and place the 4th in 4th place.<»

25
Q

STDDEV_POP

A

STDDEV_POP() Returns numeric population standard deviation of x.

26
Q

STDDEV_SAMP

A

STDDEV_SAMP() Returns the numeric sample standard deviation of x.

27
Q

VAR_POP

A

VAR_POP() Returns population variance of x.

28
Q

VAR_SAMP

A

VAR_SAMP() Returns sample variance of x.

29
Q

HAVING

A

HAVING() Works like WHERE but for GROUP functions (WHERE can’t use group functions). Comes after GROUP BY

30
Q

ROLLUP

A

Used to return superaggregate rows. Will return an extra row of subtotals for each group. NULL values will be counted separately for each group and will have their own row unless using an NVL function.

31
Q

CUBE

A

Creates subtotals for all possible combinations of grouping columns.

32
Q

How many levels of nesting are allowed with group functions?

A

Any number for single-row within group, only one for group within group.