KDB:如何在表的每个记录上打印字符串文字?

时间:2018-11-26 17:19:03

标签: kdb

如何选择带有字符串文字值的表?

tab:flip `items`sales`prices!(`nut`bolt`cam`cog;6 8 0 3;10 20 15 20)

select a:"abcdef", items, sales from tab

预期输出:

    a        items sales prices
    ----------------------------
    "abcdef" nut   6     10
    "abcdef" bolt  8     20
    "abcdef" cam   0     15
    "abcdef" cog   3     20

3 个答案:

答案 0 :(得分:2)

如果只想向表中添加新列;在这里,我们使用KDB隐藏的public void cal() { int[,] a = new int[3, 3]; int row11; int row12; int row13; int row21; int row22; int row23; int row31; int row32; int row33; row11 = Convert.ToInt32(textBox1.Text); row12 = Convert.ToInt32(textBox2.Text); row13 = Convert.ToInt32(textBox3.Text); row21 = Convert.ToInt32(textBox4.Text); row22 = Convert.ToInt32(textBox5.Text); row23 = Convert.ToInt32(textBox6.Text); row31 = Convert.ToInt32(textBox7.Text); row32 = Convert.ToInt32(textBox8.Text); row33 = Convert.ToInt32(textBox9.Text); a[0, 0] = row11; a[0, 1] = row12; a[0, 2] = row13; a[1, 0] = row21; a[1, 1] = row22; a[1, 2] = row23; a[2, 0] = row31; a[2, 1] = row32; a[2, 2] = row33; int sum = (row11 * ((row22 * row33) - (row23 * row32))) - (row12 * ((row21 * row33) - (row23 - row31))) + (row13 * ((row21 * row32) - (row22 - row31))); textBox19.Text = sum.ToString(); 列来对记录进行计数。

from z3 import *

s = Solver()

# One boolean for each sign's correctness:
sign1, sign2, sign3 = Bools('sign1 sign2 sign3')

# If True, then it has a tiger, otherwise it has a lady
room1, room2, room3 = Bools('room1 room2 room3')

# Room I: Tiger is in this room.
s.add(sign1 == room1)

# Room II : Lady is in this room.
s.add(sign2 == Not(room2))

# Room III: A tiger is in Room II.
s.add(sign3 == room2)

# At most one of the signs are true
s.add(If(sign1, 1, 0) + If(sign2, 1, 0) + If(sign3, 1, 0) <= 1)

# There is exactly one lady:
s.add(If(room1, 0, 1) + If(room2, 0, 1) + If(room3, 0, 1) == 1)

# There are exactly two tigers:
s.add(If(room1, 1, 0) + If(room2, 1, 0) + If(room3, 1, 0) == 2)

while s.check() == sat:
    m = s.model()
    print m
    s.add(Not(And([v() == m[v] for v in m])))

答案 1 :(得分:1)

您可以执行以下操作:

 q) update a:count[t]#enlist "abcdef" from t:select items, sales from tab

如果您有where子句,这也将起作用:

  q)update a:count[t]#enlist "abcdef" from t:select items, sales from tab where sales<4

输出:

     a      items sales prices
    ----------------------------
    "abcdef" cam   0     15
    "abcdef" cog   3     20

答案 2 :(得分:1)

您可以在select语句中进行操作,前提是虚构的列不在第一位

q)select items,a:count[i]#enlist"abcdef",sales from tab
items a        sales
--------------------
nut   "abcdef" 6
bolt  "abcdef" 8
cam   "abcdef" 0
cog   "abcdef" 3

如果首先是虚构的列,则它将值分组到需要ungroup

的列表中

另一种但不太传统的方法是使用cross

q)([]a:enlist "abcdef")cross tab
a        items sales prices
---------------------------
"abcdef" nut   6     10
"abcdef" bolt  8     20
"abcdef" cam   0     15
"abcdef" cog   3     20