日期:2014-05-18 浏览次数:20824 次
这样? select 品名,型号,sum(数量) as 合计 from kl where isnull(检验结果,'')= '合格' group by 型号,品名 order by 品名,型号
------解决方案--------------------
SELECT a.品名,a.型号,b.合计
FROM 表1 a RIGHT JOIN (select 型号,sum(数量) as 合计 from 表 where 检验结果= '合格 ' group by 型号) b ON a.型号=b.型号
ORDER BY a.型号
------解决方案--------------------
create table lingyunbi
(
品名 char(50),
型号 char(50),
数量 int,
检验结果 char(50),
到货时间 char(50)
)
delete lingyunbi
insert into lingyunbi
select '主板', 'MS6714' , 200 , '合格' , '2005-10-9' union all
select '主板' ,'MS6368' , 1000 , '不合格' , '2005-9-4' union all
select '主板' , 'MS6714' , 50 , '合格' , '2005-12-6' union all
select '显卡', '7300SE' , 500 , '合格' , ' 2006-1-4' union all
select 'cpu', 'AMD' , 300 , '合格' , ' 2006-1-4' union all
select 'cpu', 'Intel' , 800 , '合格' , ' 2006-1-4'
select 品名, 型号 ,sum(数量) as 合计 from lingyunbi where 检验结果= '合格' group by 型号,品名 order by 品名
------------------------
?? 7300SE 500
cpu AMD 300
cpu Intel 800
主板 MS6714 250