--ms sql server:
select a.日期,a.物料,a.工序,a.设备,a.班组,a.操作工,a.数量,a.单价,
(
case when b.物料种类数>1 or b.物料种类数=1 and c.设备种类数>1 and d.工序种类数=1 then 0.8 else 1 end
)as 折扣,
a.数量*a.单价*(
case when b.物料种类数>1 or b.物料种类数=1 and d.工序种类数=1 and c.设备种类数>1 then 0.8 else 1 end
) as 工资
from 表名 a left join
(select 日期,count(物料) as 物料种类数,操作工 from 表名 group by 日期,操作工) b
on a.日期=b.日期 and a.操作工=b.操作工
left join
(select 日期,count(设备) as 设备种类数,操作工 from 表名 group by 日期,操作工) c
on a.日期=c.日期 and a.操作工=c.操作工
left join
(select 日期,count(工序) as 工序种类数,操作工 from 表名 group by 日期,操作工) d
on a.日期=d.日期 and a.操作工=d.操作工
select 数量,单价,折扣,数量*单价*折扣 as '工资' from table
能看懂么
其他的东西,你没有表结构,没有人能帮你写出来