日期:2014-05-18  浏览次数:20595 次

向大家请教一个问题
向大家请教一个问题:
有两个表:
1、主表:TXSLSZ(销售流水帐)。字段有sXSDH(销售单号)、dXSSJ(销售时间)、sLSH(流水号)...
2、子表:T_XSNR(销售内容)。字段有sXSDH(销售单号)、sPCODE(商品编号)...

请教:
现在知道有一笔交易单上有商品编号为:6921555531297和6932010100019的商品,请问如何使用SQL语句得到这笔单的流水号?

------解决方案--------------------
select a.slsh,a.sxsdh from 主表 a join 子表 b on a.sxsdh=b.sxsdh where spcode= '6921555531297 ' or spcode= '6932010100019 '
------解决方案--------------------
select sLSH from txslsz t1,t_xsnr t2 where t1.sxsdh=t2.sxsdh and spcode in( '6921555531297 ', '6932010100019 ');

------解决方案--------------------
select sXLSH
from TXSLSZ a
inner join(
select sXSDH
from T_XSNR
where sPCODE in ( '6921555531297 ', '6932010100019 ')
group by sXSDH
having count(*)=2
)b
on a.sXSDH = b.sXSDH
------解决方案--------------------
SELECT a.sLSH
FROM txslsz a,t_xsnr b
WHERE a.sxsdh=b.sxsdh
AND spcode IN( '6921555531297 ', '6932010100019 ')
------解决方案--------------------
select * from TXSLSZ where exists(
select a.sXSDH,count(sPCODE) from T_XSNR a inner join T_XSNR b on a.sXSDH=b.sXSDH
where a.sPCODE= '921555531297 ' and b.sPCODE= '6932010100019 ') and a.sXSDH=TXSLSZ.sXSDH
group by a.sXSDH,b.sXSDH having count(sPCODE)=2)