select * from programfilesystem a where exists(select 1 from requestfilesystem where fileid=a.fileid and programfilename='a.doc')
大姐果然犀利! 我是不是太强调exeid=2使得我自己陷入混乱了?还有就是为什么要用select 1呢? 大姐我用第二个想法写出来了. 用的自查询,你帮忙看看 select a.programfilename from programfilesystem as a where a.fileid=(select b.fileid from programfilesystem as b where a.fileid=b.fileid and b.exeid=2) and programfilename='a.doc'
use tempdb godeclare @requestfilesystem table ( fileid int identity(1,1), requestfilename varchar(10) ); declare @programfilesystem table ( exeid int, fieldid int, programfilename varchar(50) );insert into @requestfilesystem values('ab') insert into @requestfilesystem values('bc')insert into @programfilesystem values(1,1,'a.doc') insert into @programfilesystem values(2,1,'b.doc') insert into @programfilesystem values(3,2,'b.doc') --preparing update exeid=2 -- variable exeid=2 ;With CTE as ( Select exeid, programfilename from @programfilesystem p where p.fieldid=(select fieldid from @programfilesystem where exeid=2) ) --在这里找到所有不能修改的名字, /*假设要修改的记录为exeid=2,那么除exeid=2以外的所有记录名称都不符合条件*/ select programfilename from CTE where exeid<>2
我现在终于明白select 1的意思了. 你的查询语句是查询所有programfilesystem下所有programfilename='a.doc'(因为我programfilesystem的fileid都是根据requestfilesystem中的fileid生成的)我一开始以为select 1 from就是select top 1 from 呢,原来根本就是两码事啊. 嗯,虽然跟我提问的问题还是有点出入,但还是受教了.thx
*
from
programfilesystem a
where
exists(select 1 from requestfilesystem where fileid=a.fileid and programfilename='a.doc')
大姐果然犀利! 我是不是太强调exeid=2使得我自己陷入混乱了?还有就是为什么要用select 1呢?
大姐我用第二个想法写出来了.
用的自查询,你帮忙看看
select a.programfilename from programfilesystem as a where a.fileid=(select b.fileid from programfilesystem as b where a.fileid=b.fileid and b.exeid=2) and programfilename='a.doc'
use tempdb
godeclare @requestfilesystem table
(
fileid int identity(1,1),
requestfilename varchar(10)
);
declare @programfilesystem table
(
exeid int,
fieldid int,
programfilename varchar(50)
);insert into @requestfilesystem values('ab')
insert into @requestfilesystem values('bc')insert into @programfilesystem values(1,1,'a.doc')
insert into @programfilesystem values(2,1,'b.doc')
insert into @programfilesystem values(3,2,'b.doc')
--preparing update exeid=2
-- variable exeid=2
;With CTE
as
(
Select exeid, programfilename
from @programfilesystem p
where p.fieldid=(select fieldid from @programfilesystem where exeid=2)
)
--在这里找到所有不能修改的名字,
/*假设要修改的记录为exeid=2,那么除exeid=2以外的所有记录名称都不符合条件*/
select programfilename
from CTE
where exeid<>2
我现在终于明白select 1的意思了.
你的查询语句是查询所有programfilesystem下所有programfilename='a.doc'(因为我programfilesystem的fileid都是根据requestfilesystem中的fileid生成的)我一开始以为select 1 from就是select top 1 from 呢,原来根本就是两码事啊.
嗯,虽然跟我提问的问题还是有点出入,但还是受教了.thx