--建立测试环境
Create Table 表(生产日期 varchar(10),零件号 varchar(10),数量 integer,属性 varchar(10))
--插入数据
insert into 表
select '2005/1/1','a','100','Good' union
select '2005/2/2','a','130','scrap' union
select '2005/2/4','a','200','Good'
--测试语句
select 零件号,Good=sum(case when 属性='Good' then 数量 end),
scrap=sum(case when 属性='scrap' then 数量 end)
from 表 group by 零件号
--删除测试环境
Drop Table 表
/*
零件号 Good scrap
---------- ----------- -----------
a 300 130