我有4个带列的表,如下所示表1:PART带以下列|PID|PCODE|PNAME|MID|
表2:MAN,具有以下列|MID|MCODE|MNAME|MVALID|
表3:LVL,列如下|PID |数量|
表4:AVAIL,列如下|MID|MAVAILABLE|
我想要<PCODE>,<MCODE>,<QUANTITY>,<MNAME>
形式的查询输出,所以我尝试了以下sql:
select
part.pcode,
man.mcode,
lvl.quantity,
man.mname
from man
inner join avail on man.mid = avail.mid
inner join part on man.mid = avail.mid
inner join lvl on part.pid = lvl.pid
where PNAME like '%phyll%'
and MAVAILABLE = 'YES'
然而,当我执行时,我需要很长时间才能终止,此外,表的最大行数为500。我哪里出错了?
编辑:新问题:使用WHERE
子句(仅使用此语句,where PNAME like '%phyll%'
可以减少执行时间并起作用,但添加and MAVAILABLE = 'YES'
以筛选包含单词YES的MAVAILABLE行会产生0个结果,但列中有许多结果带有YES。这里有错误吗?MAVAILABLE列只包含YES或NO字符串
尝试
select
part.pcode,
man.mcode,
lvl.quantity,
man.mname
from man
inner join avail on man.mid = avail.mid
inner join part on man.mid = part.mid -- I made a change here
inner join lvl on part.pid = lvl.pid
where PNAME like '%phyll%'
and MAVAILABLE = 'YES'