我有一个SQL查询,我想在子查询中使用主查询的列值之一。如何在子查询中使用主查询列值?
查询是:
select **tool.item**, asset.id, tool.date,
(select freq from workorder
where type = 'CP' and itemnum = **tool.item**) freq, asset.pm
from tool,
asset
where too.num = asset.num
and asset.status = 'ACTIVE';
在此查询我想在子查询中使用获取tool.item值。
item assetid date pm freq
A1 1 12-NOV-15 123 freq from workorder where itemnum ='A1'
A2 2 13-NOV-15 124 freq from workorder where itemnum ='A2'
你能帮我吗? 在此先感谢。
为什么不在工作单上使用连接? – flowit
你确定你需要一个子查询吗?您期望每个工具项目有多少工单记录?如果只有1个,那么简单的加入就可以了 –