SELECT a.生产线, a.班组, a.产品类型, a.颜色, a.输入日期, IIf(Sum([s7])=0,"",Format((select sum([s7]) from 输入数据 where 生产线=a.生产线 and 班组=a.班组 and 颜色=a.颜色 and 产品类型=a.产品类型 and 输入日期=a.输入日期 and 数据来源 like "*合格")/Sum([s7]),"#.##%")) AS [S-7]
FROM 输入数据 AS a
GROUP BY a.生产线, a.班组, a.产品类型, a.颜色, a.输入日期
ORDER BY a.输入日期 DESC;