Analytics Functions Example 4: Sequence Arithmetic

Arithmetic on Sequences

Perform arithmetic operations on sequence elements. These two sequences are averaged by adding each element of high to the corresponding element of low and dividing by 2 to produce a result sequence:

 
    SELECT flattened symbol, seq_search(day, 20130101, 20130131) as Jan_2013,
        high@Jan_2013 as "high", low@Jan_2013 as "low",
        (high@Jan_2013 + low@Jan_2013) / 2 as "average"
    FROM Quote WHERE symbol='IBM';
     
    symbol  Jan_2013        high            low             average
    ------------------------------------------------------------------
    IBM     20130102        196.350006      193.800003      195.075012
    IBM     20130103        196.289993      194.440002      195.364990
    IBM     20130104        194.460007      192.779999      193.619995
    IBM     20130107        193.779999      192.339996      193.059998
    IBM     20130108        193.300003      191.610001      192.455002
    IBM     20130109        193.490005      191.649994      192.570007
    IBM     20130110        192.960007      191.279999      192.119995
    IBM     20130111        195.000000      192.899994      193.949997
    IBM     20130114        193.279999      191.750000      192.514999
    IBM     20130115        192.729996      190.389999      191.559998
    IBM     20130116        193.179993      191.350006      192.264999
    IBM     20130117        194.460007      193.240005      193.850006
    IBM     20130118        195.000000      193.800003      194.399994
    IBM     20130122        196.080002      194.009995      195.044998
    IBM     20130123        208.580002      203.360001      205.970001
    IBM     20130124        205.059998      203.080002      204.070007
    IBM     20130125        205.179993      204.130005      204.654999
    IBM     20130128        206.220001      204.289993      205.255005
    IBM     20130129        205.729996      203.639999      204.684998
    IBM     20130130        204.880005      203.190002      204.035004
    IBM     20130131        204.470001      202.960007      203.714996
     

To run this example

A sample script to demonstrate this select statement using xSQL can be run from the samples/xsql/scripts/financial directory with the following command:

     
    x 4