kdb - 基于行信息的条件更新字段
问题描述
在 KDB 我有这张表:
q)tab
items sales prices adjust factor
--------------------------------
nut 6 10 1b 1.2
bolt 8 20 1b 1.5
cam 0 15 1b 2
cog 3 20 0b 0n
nut 6 10 0b 0n
bolt 8 20 0b 0n
我想根据条件计算第四列,例如:
if[adjust; prices * factor;]
目的是得到以下结果:
items sales prices newPrices
----------------------------
nut 6 10 12
bolt 8 20 30
cam 0 15 30
cog 3 20 20
nut 6 10 10
bolt 8 20 20
有人可以帮我吗?
解决方案
我认为您正在寻找类似的东西:
q) update newPrices:?[adjust;prices*factor;prices] from tab
items sales prices adjust factor newPrices
------------------------------------------
nut 6 10 1 1.2 12
bolt 8 20 1 1.5 30
cam 0 15 1 1 15
cog 3 20 0 20
nut 6 10 0 10
bolt 8 20 0 20
推荐阅读
- rust - 如何使用 nom 执行简单的 while 循环并解析二进制数据块?
- postgresql - 删除了 geometry_columns 和 geography_columns 表
- powershell - 从 SQL Server 代理执行时永无止境的 Powershell 脚本
- c - 有没有更好的方法来定义一个预处理宏来进行位操作?
- angular - 无法解析 AddPassModal 的所有参数:(?, ?)
- vb.net - 将 NumericUpDown 设置为只读
- java - 使用反射 Java 初始化泛型类
- c# - 需要将新的空白记录(行)插入现有的 DBF 文件(dbase III 格式)
- php - PHP SoapClient 返回状态 200 没有任何响应
- asp.net-core-mvc - 从表中获取选定列的列表数据