--测试--测试数据 create table tb(a int,b varchar(10),c int,d varchar(10)) insert tb select 1,'张三','25','人事部' union all select 2,'张三','25','财务部' union all select 3,'李四','23','人事部' union all select 4,'张三','24','工程部' go--查询 select * from tb a where exists(select * from tb where b=a.b and c=a.c and a<>a.a) go--删除测试 drop table tb/*--测试结果a b c d ----------- ---------- ----------- ---------- 1 张三 25 人事部 2 张三 25 财务部(所影响的行数为 2 行) --*/
select * from t_goods where exists(select * from t_goods where itemname=t_goods.itemname and itemspec=t_goods.itemspec and itemno<>t_goods.itemno)这是我按你教我的写的,可以查不出来啊。
select * from t_goods a where exists(select * from t_goods where itemname=a.itemname and itemspec=a.itemspec and itemno<>a.itemno)
老大,还是老大,我马上给分。 以后还要请你多帮帮忙。刚学SQL没有多久。
[AS] table_aliastable_name、view_name 或 rowset_function 的别名,为方便起见而使用,或用于区分自联接或子查询中的表或视图。别名通常是一个缩短了的表名,用于在联接中引用表中的特定列。如果联接中的多个表中有相同名称的列存在,SQL Server 要求必须使用表名或别名来限定列名。(如果定义了别名则不能使用表名)。
create table tb(a int,b varchar(10),c int,d varchar(10))
insert tb select 1,'张三','25','人事部'
union all select 2,'张三','25','财务部'
union all select 3,'李四','23','人事部'
union all select 4,'张三','24','工程部'
go--查询
select * from tb a
where exists(select * from tb where b=a.b and c=a.c and a<>a.a)
go--删除测试
drop table tb/*--测试结果a b c d
----------- ---------- ----------- ----------
1 张三 25 人事部
2 张三 25 财务部(所影响的行数为 2 行)
--*/
where exists(select * from t_goods where itemname=t_goods.itemname and itemspec=t_goods.itemspec and itemno<>t_goods.itemno)这是我按你教我的写的,可以查不出来啊。
where exists(select * from t_goods where itemname=a.itemname and itemspec=a.itemspec and itemno<>a.itemno)
以后还要请你多帮帮忙。刚学SQL没有多久。