首页 > 解决方案 > KDB:如何使用一组列进行查询

问题描述

我该如何做这个相应的 SQL 查询:

select * from a where (col1, col2) in (select x, y from b)

所以如果我有

p:([]name:`John`Mary`David`James; age:52 49 18 23; hair:("black";"black";"blonde";"black"); eyes:`brown`brown`blue`brown; aa:("hello";"world";"hi";"there"))

我如何使这个查询工作:

select from p where (hair, eyes) in (
select hair, eyes from p where any aa like/:("hello";"hi")
)

标签: kdb

解决方案


的输出select hair, eyes from p where any aa like/:("hello";"hi")是一个表,因此我们需要为所需的 where 语句从hair和列创建一个表:eyes

q)select from p where ([]hair;eyes) in select hair, eyes from p where any aa like/:("hello";"hi")
name  age hair     eyes  aa
--------------------------------
John  52  "black"  brown "hello"
Mary  49  "black"  brown "world"
David 18  "blonde" blue  "hi"
James 23  "black"  brown "there"

推荐阅读