日期:2014-05-17  浏览次数:20337 次

求一个sql2000语句
现有pdkcb表,有两个盘点号,pd_hao='p130324001'  pd_hao='p130324002'
求查询出p130324001,p130324002这两个盘点号中bian_hao,pi_hao相同的品种
sql语句

------解决方案--------------------



select * from 
(select * from pdkcb where pd_hao='p130324001') t1
inner join 
(select * from pdkcb where pd_hao='p130324002') t2
on t1.bian_hao = t2.bian_hao and t1.pi_hao = t2.pihao




------解决方案--------------------

select * from (
select * from pdkcb where pd_hao in('p130324001','p130324002'))
a,
select * from pdkcb where pd_hao in('p130324001','p130324002')
b
where a.bian_hao = b.bian_hao
and a.pi_hao = b.pi_hao

------解决方案--------------------
select * from 
pdkcb  a inner join pdkcb b
on a.bian_hao = b.bian_hao and a.pi_hao = b.pihao  
where a.pd_hao='p130324001'
and b.pd_hao='p130324002'
------解决方案--------------------


select * 
from pdkcb as a 
where a.pd_hao in('p130324001','p130324002') 
and exists(select 1 from pdkcb where bian_hao=a.bian_hao and pi_hao=a.pi_hao and pd_hao <>b.pd_hao  and pd_hao in('p130324001','p130324002'))