Leo*_*nid 11 sql where inner-query kdb
有什么方法可以在子句Q中使用嵌套查询的结果where?
我正在寻找类似SQL陈述的东西.
select from food where type_id in (
select type_id from types where type_name = "fruit"
)
Run Code Online (Sandbox Code Playgroud)
select from food where type_id in (exec type_id from types where type_name like "fruit")
Run Code Online (Sandbox Code Playgroud)
除了传递给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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5015 次 |
| 最近记录: |