vwap

vwap — Dynamic aggregate function for vwap

SYNOPSIS

vwap (price,quantity)

DESCRIPTION

The function name is case-sensitive. This function only exists for dynamic aggregation.

Computes a value for each record from the base table and returns the volume-weighted average price. Argument quantity must be of type integer. Argument price must be of type double.The returned price is type double.

EXAMPLE

This example shows you how to find the volume-weighted average for all green toys and group them by sku.

Load and run the Hello LiveView sample as delivered with LiveView. Follow these steps:

  1. Start StreamBase Studio in the SB Authoring perspective.

  2. Load the Hello LiveView sample.

    1. Select FileLoad StreamBase Sample from Studio's top-level menu.

    2. In the Load StreamBase Projects dialog, open the StreamBase LiveView category.

    3. Select the sample whose description is Shows a simple Hello World application and press OK.

    The Hello LiveView sample loads into Studio with the project name sample_lv-helloliveview.

  3. In the Package Explorer view, select the name of the project, right-click, and from the context menu, select Run AsStreamBase LiveView Project. The Console view shows several messages as the LiveView Server compiles the project and starts.

  4. When you see message All tables have been loaded in the Console view, start LiveView Desktop:

    • On Windows, run StartAll ProgramsStreamBase LiveView n.mLiveView Desktop.

    • On Linux, run the following command:

      /opt/streambase/liveview/desktop/liveview &
      

    This opens the LiveView Desktop start dialog.

  5. In the LiveView Desktop start dialog, select the radio button for Download and click Select.

  6. Select the workspace named Hello LiveView and version Latest (1.0).

  7. Click OK. This returns you to the LiveView Desktop start dialog. The Download field now contains Hello LiveView (Latest).

  8. Click OK.

Now you can create a vwap query from LiveView Desktop. Follow these steps:

  1. Select the Items table from the Tables pane of the LiveView Tables view.

  2. In the Query on Items pane, enter the following:

    1. In the Select window, enter:

      sku, vwap(lastSoldPrice,quantityRemaining) AS myVwap
      
    2. In the Query window, enter the following:

      color='green' and category='toys' group by sku
      
    3. Click Start New Query.