select selfcond
from flowstep a join runflow b on a.flowid=b.flowid
join runstep c on b.runflowid=c.runflowid
from flowstep a join runflow b on a.flowid=b.flowid
join runstep c on b.runflowid=c.runflowid
from flowstep a join runflow b on a.flowid=b.flowid
join runstep c on b.runflowid=c.runflowid
where b.runflowid=100,stepid=2
表1:flowstep(flowid,stepid,selfcond)
表2:runflow(flowid,runflowid,flowname)
表3:runstep(runflowid,stepid,stepname)
括号前是表名,括号间是字段名。我现在要得到runflowid=100,stepid=2的selfcond和stepname,用一个sql语句怎样写?谢谢!
from flowstep
where flowid in
(select flowid
from runflow
where runflowid in
(select runflowid
from runstep
where runflowid=100 and stepid=2))
你看哪个查询的效率高用哪个!
from flowstep a join runflow b on a.flowid=b.flowid
join runstep c on b.runflowid=c.runflowid
where b.runflowid=100,stepid=2试试!
是mysql数据库
from runstep a join runflow b
on a.runflowid=b.runflowid
join flowstep c
on b.flowid=c.flowid
where a.runflowid=100 and a.stepid=2
不知道你说的stepid是哪个表的,如果是flowstep的,那么就应该改成:
select c.selfcond,a.runflowid,a.stepid
from runstep a join runflow b
on a.runflowid=b.runflowid
join flowstep c
on b.flowid=c.flowid
where a.runflowid=100 and c.stepid=2
from runstep a join runflow b
on a.runflowid=b.runflowid
join flowstep c
on b.flowid=c.flowid
where a.runflowid=100 and a.stepid=2
不知道你说的stepid是哪个表的,如果是flowstep的,那么就应该改成:
select c.selfcond,a.runflowid,a.stepid
from runstep a join runflow b
on a.runflowid=b.runflowid
join flowstep c
on b.flowid=c.flowid
where a.runflowid=100 and c.stepid=2
insert into flowstep3 select '1','3','3'
union all select '2','2','1'
union all select '3','2','2'
union all select '4','3','2'
go
create table runflow3 (flowid varchar(10),runflowid varchar(20),flowname varchar(20))
insert into runflow3 select '1','100','3'
union all select '2','200','2'
union all select '3','100','6'
union all select '4','40','2'
go
create table runstep3 (runflowid varchar(10),stepid varchar(20),stepname varchar(20))
insert into runflow3 select '1','100','3'
union all select '2','200','2'
union all select '3','100','6'
union all select '4','40','2'
--查询:
select selfcond,stepname
from flowstep3 a join runflow3 b on a.flowid=b.flowid
join runstep3 c on b.runflowid=c.runflowid
where b.runflowid=100 and a.stepid=2
结果就是你象要的