首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

:怎么查询同时满足二个条件

2012-09-04 
请教高手:如何查询同时满足二个条件create table Detail(IDint,contractNovarchar(50),CustCodevarchar(50

请教高手:如何查询同时满足二个条件
create table Detail
(
ID int,
contractNo varchar(50),
CustCode varchar(50),
Amount numeric(18,3)
)


insert into detail(ContractNo,CustCode,Amount) values('ds20111230','ws001',1000)
insert into detail(ContractNo,CustCode,Amount) values('ds20111230','ws002',1300)
insert into detail(ContractNo,CustCode,Amount) values('ds20111231','ws003',1000)
insert into detail(ContractNo,CustCode,Amount) values('ds20111232','ws002',1000)
insert into detail(ContractNo,CustCode,Amount) values('ds20111233','ws002',1000)
insert into detail(ContractNo,CustCode,Amount) values('ds20111234','ws001',1000)
insert into detail(ContractNo,CustCode,Amount) values('ds20111235','ws001',1000)

请高手指教如何查询: 要查询ContractNo='ds20111230' 所对应的CustCode和Amount同时重复的其它ContractNo
比如:ContractNo='ds20111230' 所对应的CustCode='ws001'和Amount=1000和
  CustCode='ws002'和Amount=1300


也就是说查询:CustCode='ws001'和Amount=1000重复的记录和CustCode='ws002'和Amount=1300重复的记录



   





[解决办法]

SQL code
select *from Detail twhere exists (select 1 from Detail where CustCode=t.CustCode and Amount=t.Amount and ContractNo='ds20111230')
[解决办法]
探讨

SQL code

select *
from Detail t
where exists (select 1 from Detail where CustCode=t.CustCode and Amount=t.Amount and ContractNo='ds20111230')

热点排行