max/Max
max/Max — Static and dynamic aggregate functions for max
DESCRIPTION
Computes a value for each record returned by the query predicate or from the base table and returns the maximum of the values.
-
For static aggregation, aggregates refresh as data in the active (source) table is updated.
-
For dynamic aggregation, aggregates refresh as rows are returned by the query predicate.
Expression expr
must be a StreamBase
expression of numeric type. The returned average is a value of that type.
The function name is case-sensitive. The Title-cased syntax is for static (table-based) aggregation. The lower-cased syntax is for dynamic (query-based) aggregation. See Data Aggregation for more information on aggregation in LiveView.
EXAMPLE
This example shows you how to find the largest price of several groups of items.
Load and run the Hello LiveView sample as delivered with LiveView. Follow these steps:
-
Start StreamBase Studio in the SB Authoring perspective.
-
Load the Hello LiveView sample.
-
Select
→ from Studio's top-level menu. -
In the Load StreamBase Projects dialog, open the StreamBase LiveView category.
-
Select the sample whose description is
Shows a simple Hello World application
and press .
The Hello LiveView sample loads into Studio with the project name
sample_lv-helloliveview
. -
-
In the Package Explorer view, select the name of the project, right-click, and from the context menu, select
→ . The Console view shows several messages as the LiveView Server compiles the project and starts. -
When you see message
All tables have been loaded
in the Console view, start LiveView Desktop:-
On Windows, run
→ → → . -
On Linux, run the following command:
/opt/streambase/liveview/desktop/liveview &
This opens the LiveView Desktop start dialog.
-
-
In the LiveView Desktop start dialog, select the radio button for Download and click .
-
Select the workspace named Hello LiveView and version Latest (1.0).
-
Click
. This returns you to the LiveView Desktop start dialog. The Download field now contains Hello LiveView (Latest). -
Click
.
Now you can create a query that finds the largest value of the lastSoldPrice field from the Items table, grouping by category and color. Follow these steps:
-
Select the ItemsSales table from the Tables pane of the LiveView Tables view.
-
In the Query on ItemsSales pane, enter the following:
-
In the Select window, enter:
category,Item, max(lastSoldPrice) AS maxLastSoldPrice
-
In the Query window, enter the following:
group by category, Item
-
Click
.
-
The query results open, by default, in a grid view. The maxPrice field is the largest value of the lastSoldPrice field in the Items table. LiveView Server recalculates the maximum value whenever the rows returned by the query predicate change and updates as necessary.
The query output groups by category and Item, so the aggregate selects all items with the same category and color and performs the aggregation on the values of the lastSoldPrice field.