--sql 2005
--生成楼主所说结果集查询语句
select a.code,a.销售情况,a.进货渠道,sum(b.价格) 累加金额,
stuff((select ','+名称 from teb2 where code = b.code for xml path('')),1,1,'') 累叠名称
from teb1 a join teb2 b on a.code = b.code
where exists (select 1 from teb2 where code = b.code and 名称 = '啤酒')
--只查询啤酒相关数据
select *
from teb1 a join teb2 b on a.code = b.code
where exists (select 1 from teb2 where code = b.code and 名称 = '啤酒')
------解决方案--------------------