我写了俩小时才测试成功的,你不采纳我也没话说了:
select * from ((select T1.工程队,T1.职员,T1.物料内码,T2.物料名称,T2.规格型号,T1.单价,T1.数量,T1.金额
from T1 left join T2 on T1.物料内码=T2.物料内码
where T1.工程队='工程队1' and T1.职员='职员a')
union all
select T.工程队,'a小计','','','','',T.数量,T.金额 from (select T1.工程队,'a小计','','','','',T1.数量,T1.金额
from T1 left join T2 on T1.物料内码=T2.物料内码
where T1.工程队='工程队1' and T1.职员='职员a' ) T)
union all
select * from ((select T1.工程队,T1.职员,T1.物料内码,T2.物料名称,T2.规格型号,T1.单价,T1.数量,T1.金额
from T1 left join T2 on T1.物料内码=T2.物料内码
where T1.工程队='工程队1' and T1.职员='职员b')
union all
select T.工程队,'b小计','','','','',T.数量,T.金额 from (select T1.工程队,'a小计','','','','',T1.数量,T1.金额
from T1 left join T2 on T1.物料内码=T2.物料内码
where T1.工程队='工程队1' and T1.职员='职员b') T)
union all
select T.工程队,'队1合计','','','','',to_char(sum(T.数量)),to_char(sum(T.金额)) from
(select T1.工程队,'队1合计','','','','',T1.数量,T1.金额
from T1 left join T2 on T1.物料内码=T2.物料内码) T
group by T.工程队 having T.工程队='工程队1'
union all
select T1.工程队,T1.职员,T1.物料内码,T2.物料名称,T2.规格型号,T1.单价,T1.数量,T1.金额
from T1 left join T2 on T1.物料内码=T2.物料内码
where T1.工程队='工程队2' and T1.职员='职员c'
union all
select T.工程队,'c小计','','','','',to_char(sum(T.数量)),to_char(sum(T.金额)) from
(select T1.工程队,'c小计','','','','',T1.数量,T1.金额
from T1 left join T2 on T1.物料内码=T2.物料内码) T
group by T.工程队 having T.工程队='工程队2'
union all
select T.工程队,'队2合计','','','','',to_char(sum(T.数量)),to_char(sum(T.金额)) from
(select T1.工程队,'队2合计','','','','',T1.数量,T1.金额
from T1 left join T2 on T1.物料内码=T2.物料内码) T
group by T.工程队 having T.工程队='工程队2'
SELECT日期,(SELECTSUM(工资)FROMat2WHEREt2.日期