在KDB中选择非空字符串行

在KDB中选择非空字符串行,kdb,Kdb,我只想选择“详细信息”为非空的行。看起来很简单,但不是我不能让它工作 q)tab items sales prices detail ------------------------- nut 6 10 "blah" bolt 8 20 "" cam 0 15 "some text" cog 3 20 "" nut 6 10 "" bolt 8 20

我只想选择“详细信息”为非空的行。看起来很简单,但不是我不能让它工作

q)tab

items sales prices detail
-------------------------
nut   6     10     "blah"    
bolt  8     20     ""
cam   0     15     "some text"    
cog   3     20     ""    
nut   6     10     ""    
bolt  8     20     ""    
这会使所有行保持静止

或者我试过了

q) select from tab where count[detail] > 0
这给了我类型错误


如何查询KDB中的非空字符串字段?

当您需要按行执行检查时,请使用
每个

q) select from tab where not null detail 
请分别使用副词:

items sales prices detail     
------------------------------
nut   6     10     "blah"     
cam   0     15     "some text"

q)从([]细节:(“废话”;“一些文本”)中选择,其中0我将使用以下方法

q)select from ([]detail:("blah";"";"some text")) where 0<count each detail
detail     
-----------
"blah"     
"some text"

将每个细节与空字符串进行比较。使用
not null detail
的方法不起作用,因为Q将字符串视为字符数组,并检查每个数组元素是否为null。例如,
null“abc”
返回布尔数组
000b
,但where子句要求每个“行”使用单个布尔值而不是使用副词,您可以使用


如果表不大,另一种检查方法是将其转换为
where
子句中的
symbol

q)select from tab where not detail like ""

  items sales prices detail
  ------------------------------
  nut   1     10     "blah"
  cam   5     9      "some text"

谢谢你的详细解释。现在我更好地理解了底层结构。
select from tab where not detail~\:""
q)select from tab where not detail like ""

  items sales prices detail
  ------------------------------
  nut   1     10     "blah"
  cam   5     9      "some text"
q)select from ([]detail:("blah";"";"some text")) where `<>`$detail 
detail
-----------
"blah"
"some text"
q)select from ([]detail:("blah";"";"some text")) where not null `$detail 
detail
-----------
"blah"
"some text"