在子句Q
中使用嵌套查询的结果有哪些方法?where
我正在寻找类似于SQL
声明的东西。
select from food where type_id in (
select type_id from types where type_name = "fruit"
)
在子句Q
中使用嵌套查询的结果有哪些方法?where
我正在寻找类似于SQL
声明的东西。
select from food where type_id in (
select type_id from types where type_name = "fruit"
)
select from food where type_id in (exec type_id from types where type_name like "fruit")
除了传递给in谓词并使用 like 函数进行字符串相等之外,您的查询几乎是正确的。当它只接受一个列表时,您正在传递一个表。要将查询作为列表发送,我使用exec来完成这项工作。
虽然这是您问题的直接答案,但最好的方法可能是外键:
q)types:([type_id:`apple`orange`cucumber]type_name:`fruit`fruit`vegetable)
q)food:([type_id:`types$`apple`orange`cucumber]price:3?2.)
q)meta food
c | t f a
-------| ---------
type_id| s types
price | f
q)select from food where type_id.type_name=`fruit
type_id| price
-------| ---------
apple | 0.4593231
orange | 1.383906
q)
另一种方法:
select from food where type_id in (select type_id from types where type_name like "fruit")[`type_id]