你的要求是不是这样:将表A中每个单号在表B中每个项目的金额作为一列,如果这样可以试试下面的语句。
Select 单号 as 表A项目号,
isnull(Select 项目金额 from 表b as b where a.单号=b.单号 and b.项目号='1'),0) as 1,
isnull(Select 项目金额 from 表b as b where a.单号=b.单号 and b.项目号='2'),0) as 2,
isnull(Select 项目金额 from 表b as b where a.单号=b.单号 and b.项目号='3'),0) as 3
from 表A as a
group by 单号
Order By 单号