create table cj(编号 int,姓名 varchar(10),语文 int,数学 int) insert into cj select 1,'aa',12,34 insert into cj select 2,'马超',12,34 insert into cj select 3,'cc',12,34 insert into cj select 4,'dd',24,34 insert into cj select 5,'bb',24,34select 编号,姓名,语文,数学 from cj a where exists(select 1 from cj where 姓名<>a.姓名 and 数学=a.数学 and 语文=a.语文 and 姓名='马超')drop table cj
select 编号,姓名,语文,数学 from cj a where 姓名='马超' and exists (select 语文,数学 from cj where 语文=a.语文 and 数学=a.数学)
编正一下~select 编号,姓名,语文,数学 from cj a where exists (select 语文,数学 from cj where 语文=a.语文 and 数学=a.数学 and 姓名='马超')
select 编号,姓名,语文,数学 from cj where (语文,数学)=(select 语文,数学 from cj where 姓名='马超') 这是什么语法啊……寒一个先……declare @yw,@sx doubleselect @yw =语文,@sx = 数学 from cj where 姓名='马超' select 编号,姓名,语文,数学 from cj where 语文 = @yw and 数学 = @sx and 姓名<> '马超'
在子查询中求出'马超'的各项值,同时排除主查询中=马超的可能,这样写行吗? -------------------------------------------------------------------------------- select 编号,姓名,语文,数学 from CJ A where exists(select * from CJ where 姓名=马超 and 数学=a.数学 and 语文=a.语文 and A.姓名<>姓名)
from cj
where 姓名='马超'
insert into cj select 1,'aa',12,34
insert into cj select 2,'马超',12,34
insert into cj select 3,'cc',12,34
insert into cj select 4,'dd',24,34
insert into cj select 5,'bb',24,34select 编号,姓名,语文,数学 from cj a where exists(select 1 from cj where 姓名<>a.姓名 and 数学=a.数学 and 语文=a.语文 and 姓名='马超')drop table cj
from cj a
where 姓名='马超' and exists (select 语文,数学 from cj where 语文=a.语文 and 数学=a.数学)
from cj a
where exists (select 语文,数学 from cj where 语文=a.语文 and 数学=a.数学 and 姓名='马超')
from cj
where (语文,数学)=(select 语文,数学 from cj where 姓名='马超')
这是什么语法啊……寒一个先……declare @yw,@sx doubleselect @yw =语文,@sx = 数学 from cj where 姓名='马超' select 编号,姓名,语文,数学 from cj where 语文 = @yw and 数学 = @sx and 姓名<> '马超'
--------------------------------------------------------------------------------
select 编号,姓名,语文,数学 from CJ A where exists(select * from CJ where 姓名=马超 and 数学=a.数学 and 语文=a.语文 and A.姓名<>姓名)