KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy qSQL questions _ where clause and exec results Reply To: qSQL questions _ where clause and exec results

  • rocuinneagain

    Member
    May 21, 2024 at 3:00 pm

    1. qSQL has some differences to q.

    https://code.kx.com/q/ref/select/

    “select is a qSQL query template and varies from regular q syntax.”

    https://code.kx.com/q/basics/qsql/#where-phrase

    “Efficient Where phrases start with their most stringent tests.”

    Each where clause is it’s own expression. You can see inside [] the expression are executed left to right but within each expression the code is executed right to left.

    q)[(show 2;show 1);(show 4;show 3);(show 6;show 5)];
    1
    2
    3
    4
    5
    6

    2.

    https://code.kx.com/q/basics/funsql/#group-by-column

    “b is a column name. The result is a dictionary.”

    https://code.kx.com/q/basics/funsql/#group-by-columns

    “b is a list of column names. … returns a dictionary”

    https://code.kx.com/q/basics/funsql/#group-by-a-dictionary

    “b is a dictionary. Result is a dictionary in which the key is a table with columns as specified by b …”

    If you parse the queries you can see that sym:sym is group by dictionary

    q)parse"exec first open, last close by sym from daily where sym like \"*L\""
    ?
    `daily
    ,,(like;`sym;"*L")
    ,`sym
    `open`close!((*:;`open);(last;`close))

    vs:

    q)parse"exec first open, last close by sym:sym from daily where sym like \"*L\""
    ?
    `daily
    ,,(like;`sym;"*L")
    (,`sym)!,`sym
    `open`close!((*:;`open);(last;`close))