日期:2014-05-18 浏览次数:20513 次
--原始数据:@A declare @A table(StoveNo int,PotNo int,SamplingCause varchar(10)) insert @A select 123,67,'取样成功' union all select 123,68,'取样成功' union all select 123,45,'取样成功' union all select 124,98,'取样成功' union all select 124,67,'取样成功' union all select 124,56,'取样不成功' union all select 223,34,'取样成功' union all select 223,87,'取样不成功' union all select 223,90,'取样不成功' union all select 236,34,'取样成功' union all select 236,87,'取样成功' union all select 236,90,'取样不成功' select 成功=ltrim(cn)+'个罐',炉数=count(*) from (select StoveNo,cn=count(*) from @A where SamplingCause='取样成功' group by StoveNo) a group by cn /* 成功 炉数 ---------------- ----------- 1个罐 1 2个罐 2 3个罐 1 */