SQL Sequence Sort Function

The seq_sort() function produces a sequence ordered according to the second argument which is a character string value of either ‘asc’ or ‘desc’. In this example desc_volume (sorted in descending order) is then used to project the close prices (by implicitly calling seq_order_by() using the “@” operator) for the corresponding elements onto the result sequence close_by_volume.

Following is an example script demonstrating the seq_sort() function:

 
    SELECT symbol, seq_search(day, 20130101, 20130331) as Q1_13,
        seq_sort(volume@Q1_13, 'desc') as desc_volumes,
        close@desc_volumes as "close_by_desc_volume"
    FROM Quote WHERE symbol='SYM0';
     
    symbol
    Q1_13{}
    desc_volumes{}
    close_by_desc_volume{}
    ------------------------------------------------------------------------------
    SYM0
    {20130101, 20130104, 20130106, 20130110, 20130123, 20130125, 20130129,
      20130213, 20130214, 20130216, 20130311, 20130326}
    {808, 805, 732, 450, 420, 402, 385,
      367, 335, 77, 69, 48, 45}
    {45.790001, 80.320000, 67.870003, 29.940001, 37.279999, 53.459999, 25.920000,
      80.919998, 62.830002, 43.849998, 57.730000, 50.369999, 74.730003}
     

Sample script

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

     
    g 11