Skip to main content

PU_MODE

Description

Calculates the mode of the specified source column for each element in the given target table. For multi-modal input, where there are several result candidates, the element with the smallest value is chosen. For elements of type STRING, the smallest value is determined by its lexicographical order.

Syntax

PU_MODE ( target_table, source_table.column [, filter_expression] )
  • target_table: The table to which the aggregation result should be pulled. This can be:

  • source_table.column: The column which should be aggregated for every row of the target_table.

  • filter_expression (optional): An optional filter expression to specify which values of the source_table.column should be taken into account for the aggregation.

NULL handling

If no value in the source table column exists for the element in the target table (either because all values of the source table are filtered out, or because no corresponding value exists in the first place), NULL will be returned. NULL values in the source table column are treated as if the row does not exist.

Examples

[1]

Calculate the mode of the case table values for each company code:

Query

Column1

"caseTable"."companyCode"

Column2

PU_MODE ( "companyDetail" , "caseTable"."value" )

Input

Output

caseTable

caseId : string

companyCode : string

value : int

'1'

'001'

200

'2'

'001'

200

'3'

'001'

100

'4'

'002'

200

'5'

'002'

150

'6'

'002'

150

'7'

'003'

150

'8'

'003'

500

'9'

'003'

500

'10'

'003'

200

companyDetail

companyCode : string

country : string

'001'

'DE'

'002'

'DE'

'003'

'DE'

Foreign Keys

companyDetail.companyCode

caseTable.companyCode

Result

Column1 : string

Column2 : int

'001'

200

'001'

200

'001'

200

'002'

150

'002'

150

'002'

150

'003'

500

'003'

500

'003'

500

'003'

500

[2]

Calculate the mode of the case table values for each company code:

Query

Column1

"caseTable"."companyCode"

Column2

PU_MODE ( "companyDetail" , "caseTable"."value" )

Input

Output

caseTable

caseId : string

companyCode : string

value : int

'1'

'001'

100

'2'

'001'

200

'3'

'001'

300

'4'

'002'

400

'5'

'002'

500

'6'

'002'

600

'7'

'003'

700

'8'

'003'

800

'9'

'003'

900

'10'

'003'

1000

companyDetail

companyCode : string

country : string

'001'

'DE'

'002'

'DE'

'003'

'US'

Foreign Keys

companyDetail.companyCode

caseTable.companyCode

Result

Column1 : string

Column2 : int

'001'

100

'001'

100

'001'

100

'002'

400

'002'

400

'002'

400

'003'

700

'003'

700

'003'

700

'003'

700

[3]

Find the most frequent value per data type.

Query

Column1

PU_MODE ( "group" , "values"."integer" )

Column2

PU_MODE ( "group" , "values"."string" )

Column3

PU_MODE ( "group" , "values"."float" )

Column4

PU_MODE ( "group" , "values"."date" )

Input

Output

group

id : int

1

2

3

4

values

group : int

integer : int

string : string

float : float

date : date

1

1

'A'

1.0

Wed Jan 01 2025 00:00:00.000

2

2

'B'

2.0

Thu Jan 02 2025 00:00:00.000

2

3

'C'

3.0

Fri Jan 03 2025 00:00:00.000

2

3

'C'

3.0

Fri Jan 03 2025 00:00:00.000

3

5

'E'

5.0

Sun Jan 05 2025 00:00:00.000

3

4

'D'

4.0

Sat Jan 04 2025 00:00:00.000

4

null

null

null

null

Foreign Keys

group.id

values.group

Result

Column1 : int

Column2 : string

Column3 : float

Column4 : date

1

'A'

1.0

Wed Jan 01 2025 00:00:00.000

3

'C'

3.0

Fri Jan 03 2025 00:00:00.000

4

'D'

4.0

Sat Jan 04 2025 00:00:00.000

null

null

null

null

[4]

PU-functions can be used inside another aggregation function. In this example, the maximum value of all mode case table values for each company code is calculated:

Query

Column1

MAX ( PU_MODE ( "companyDetail" , "caseTable"."value" ) )

Input

Output

caseTable

caseId : int

companyCode : string

value : int

1

'001'

600

2

'001'

400

3

'001'

200

4

'002'

300

5

'002'

300

6

'003'

200

companyDetail

companyCode : string

country : string

'001'

'DE'

'002'

'DE'

'003'

'US'

Foreign Keys

companyDetail.companyCode

caseTable.companyCode

Result

Column1 : int

300

[5]

Calculate the mode of the case table values for each company code. Only consider cases with an ID larger than 2:

Query

Column1

"companyDetail"."companyCode"

Column2

PU_MODE ( "companyDetail" , "caseTable"."value" , "caseTable"."caseID" > 2 )

Input

Output

caseTable

caseId : int

companyCode : string

value : int

1

'001'

600

2

'001'

400

3

'001'

200

4

'002'

300

5

'002'

300

6

'003'

200

companyDetail

companyCode : string

country : string

'001'

'DE'

'002'

'DE'

'003'

'US'

Foreign Keys

companyDetail.companyCode

caseTable.companyCode

Result

Column1 : string

Column2 : int

'001'

200

'002'

300

'003'

200

[6]

Calculate the sum of the case table values for each company code. Only consider cases with an ID larger than 3. All case table values for companyCode '001' are filtered out, which means that in this case, NULL is returned.

Query

Column1

"companyDetail"."companyCode"

Column2

PU_MODE ( "companyDetail" , "caseTable"."value" , "caseTable"."caseID" > 3 )

Input

Output

caseTable

caseId : int

companyCode : string

value : int

1

'001'

600

2

'001'

400

3

'001'

200

4

'002'

300

5

'002'

300

6

'003'

200

companyDetail

companyCode : string

country : string

'001'

'DE'

'002'

'DE'

'003'

'US'

Foreign Keys

companyDetail.companyCode

caseTable.companyCode

Result

Column1 : string

Column2 : int

'001'

null

'002'

300

'003'

200

See also: