Analytics Functions Example 12: Sort

Sort Sequence Elements

Show close and volume values in descending order by volume:

     
    SELECT symbol, 
        seq_sort(volume, 'desc') as desc_volumes, 
        close@desc_volumes
    FROM Quote WHERE symbol='SYM0';
 
    symbol
    desc_volumes{}
    close{}
    ------------------------------------------------------------------------------
    IBM
    {12530410, 7936544, 7159219, 5830566, 5505584, 4689998, 4559773,
    4447108, 4234226, 4185545, 4172922, 4172034, 3923051, 3884317,
    3884254, 3880567, 3845476, 3807706, 3752999, 3715311, 3700786,
    3693365, 3644876, 3636837, 3627887, 3624103, 3617058, 3608049,
    3594899, 3592096, 3391562, 3380159, 3371154, 3358887, 3356946,
    3309434, 3294126, 3242463, 3223381, 3211997, 3198577, 3188819,
    3107976, 3091406, 3076793, 3049701, 3031457, 3028071, 3020648,
    3006125, 2998524, 2998317, 2962820, 2944651, 2893254, 2862276,
    2823615, 2461779, 2300240, 2169757}
    {204.720001, 214.919998, 196.080002, 212.259995, 215.800003, 200.830002, 194.470001,
    204.419998, 196.350006, 202.330002, 192.619995, 192.500000, 198.330002, 209.419998,
    193.649994, 194.449997, 197.509995, 206.529999, 213.300003, 199.309998, 210.380005,
    205.190002, 195.270004, 202.789993, 200.979996, 201.020004, 203.899994, 192.880005,
    208.380005, 210.550003, 199.139999, 193.990005, 205.179993, 204.970001, 212.059998,
    202.910004, 199.649994, 210.740005, 210.889999, 192.320007, 213.440002, 203.789993,
    201.089996, 203.070007, 199.740005, 210.080002, 212.080002, 192.869995, 215.059998,
    213.210007, 203.520004, 200.320007, 192.589996, 200.160004, 201.679993, 193.139999,
    204.929993, 200.039993, 212.360001, 200.089996}
     

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 12