有什么方法可以进去 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")
除了你传递给你的问题之外,你的查询几乎是正确的 在 谓词并使用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]