针对oneliner的KDB +/Q语法优化 [英] KDB+ / Q Syntax optimizations to oneliners

查看:147
本文介绍了针对oneliner的KDB +/Q语法优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绝对是q凡人.我什至会说一个q-baby.好吧,我有一个问题,如何将我的代码从单独的行放到一个直线上.我想有一种比我更优雅的解决方案.

I am definitly a q-mortal. I would even say a q-baby. Well I have some question how to put together my code from separate lines to a one-liner. I guess there is a way more elegant solution than mine.

  1. 如何在一行中编写以下语句:

  1. How to write the following statements in one line:

q)t1:(3#3)?\:`8
q)t1[;0]:`abc

  • 在此表创建中,如何添加列表中具有的另一列(如使用命令([]id:id_list;data:data_list;.....).到现在为止,我正在创建另一个表并对它们进行内部联接.我想这不是很有效:

  • In this table creation, how can I add another column which I have as list (like with the command ([]id:id_list;data:data_list;.....)). Till now I am creating another table and doing an inner join on them. I guess that's not very efficient:

    `id xkey update id:i from flip (`row1`row2!(1 2;3 4))
    

  • 推荐答案

    对于第一个,您可以这样做:

    For the 1st one you may do:

    q)`abc,/:(3#2)?\:`8
    abc jognjhck cihanjhp
    abc hkpblald aeajbddp
    abc blmjhgah ooeiogdj
    

    对于第二个,您可以将表格视为字典:

    For 2nd one you may treat the table as a dictionary:

    q)tb
    row1 row2
    ---------
    1    3   
    2    4   
    q)(tb`id): 5 6
    q)tb
    row1 row2 id
    ------------
    1    3    5 
    2    4    6 
    

    这篇关于针对oneliner的KDB +/Q语法优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆