4

看了所有的文档。为什么这不起作用?加载了与 KDB 分发一起提供的 sp.q 示例文件。我无法弄清楚这句话有什么问题。

q) \l sp.q
q)trade
date       sym time         price    size
-----------------------------------------
2007.07.23 a   04:48:52.665 73.53941 1000
2007.07.23 a   04:48:52.675 81.73358 600
2007.07.23 a   04:48:52.725 78.79526 900
2007.07.23 a   04:48:52.735 79.59502 600
2007.07.23 b   04:48:52.655 84.59765 200
2007.07.23 b   04:48:52.685 98.36199 500
2007.07.23 b   04:48:52.705 97.49875 700
2007.07.23 c   04:48:52.645 61.48308 900
2007.07.23 c   04:48:52.695 61.53192 700
2007.07.23 c   04:48:52.715 71.95405 200

q)trade:update size:300 from trade where sym=`c,price>71
'par
q)trade
date       sym time         price    size
-----------------------------------------
2007.07.23 a   04:48:52.665 73.53941 1000
2007.07.23 a   04:48:52.675 81.73358 600
2007.07.23 a   04:48:52.725 78.79526 900
2007.07.23 a   04:48:52.735 79.59502 600
2007.07.23 b   04:48:52.655 84.59765 200
2007.07.23 b   04:48:52.685 98.36199 500
2007.07.23 b   04:48:52.705 97.49875 700
2007.07.23 c   04:48:52.645 61.48308 900
2007.07.23 c   04:48:52.695 61.53192 700
2007.07.23 c   04:48:52.715 71.95405 200
4

2 回答 2

4

trade是一个分区表,这就是失败的原因。你到底想做什么?如果要在内存中创建数据的编辑副本,则需要类似

q)t:update size:300 from(select from trade)where sym=`c,price>71
q)t
date       sym time         price    size
-----------------------------------------
2007.07.23 a   04:48:52.665 73.53941 1000
2007.07.23 a   04:48:52.675 81.73358 600
2007.07.23 a   04:48:52.725 78.79526 900
2007.07.23 a   04:48:52.735 79.59502 600
2007.07.23 b   04:48:52.655 84.59765 200
2007.07.23 b   04:48:52.685 98.36199 500
2007.07.23 b   04:48:52.705 97.49875 700
2007.07.23 c   04:48:52.645 61.48308 900
2007.07.23 c   04:48:52.695 61.53192 700
2007.07.23 c   04:48:52.715 71.95405 300
q)

如果要更改磁盘上的数据,通常情况下很难。在这种特定情况下,您可以这样做:

q){.Q.dd[.Q.par[`:.;x;`trade];`]set update size:300 from(select from trade where date=x)where sym=`c,price>71}2007.07.23
`:./2007.07.23/trade/
q)\l .
q)trade
date       sym time         price    size
-----------------------------------------
2007.07.23 a   04:48:52.665 73.53941 1000
2007.07.23 a   04:48:52.675 81.73358 600
2007.07.23 a   04:48:52.725 78.79526 900
2007.07.23 a   04:48:52.735 79.59502 600
2007.07.23 b   04:48:52.655 84.59765 200
2007.07.23 b   04:48:52.685 98.36199 500
2007.07.23 b   04:48:52.705 97.49875 700
2007.07.23 c   04:48:52.645 61.48308 900
2007.07.23 c   04:48:52.695 61.53192 700
2007.07.23 c   04:48:52.715 71.95405 300
q)
于 2013-06-27T20:59:12.743 回答
2

该表按日期分区。您需要指定执行查询的日期,例如

trade:update size:300 from trade where sym=`c,price>71, date within (<d1>;<d2>)
于 2012-11-23T16:18:40.923 回答