想在SQL中,查询相关产品,按天、月和年的入库量,请帮我看看下面的查询语句的问题,修改完善一下,谢谢
select proName,Fmodel,DayInAmount,max(MonthInAmount),max(YearInAmount)
from(
select distinct t3.FName as proName,t3.Fmodel as Fmodel,sum(t1.FQty) as DayInAmount from
ICStockBill t2
join ICStockBillEntry t1 on t1.FInterID = t2.FInterID
join t_icitem t3 on t3.FItemID = t1.FItemID
join ICTransactionType t5 on t2.FTranType=t5.FID
join t_StockPlace t4 on t4.FSPID = t1.FDCSPID
where t2.FTranType = '2' and (t4.FSPID = '2' or t4.FSPID = '1') and t2.FDate = '2024-12-27'
union
select distinct t3.FName as proName,t3.Fmodel as Fmodel,sum(t1.FQty) as MonthInAmount from
ICStockBill t2
join ICStockBillEntry t1 on t1.FInterID = t2.FInterID
join t_icitem t3 on t3.FItemID = t1.FItemID
join ICTransactionType t5 on t2.FTranType=t5.FID
join t_StockPlace t4 on t4.FSPID = t1.FDCSPID
where t2.FTranType = '2' and (t4.FSPID = '2' or t4.FSPID = '1')
and t2.FDate >= '2024-12-1' and t2.FDate <= '2024-12-27'
union
select distinct t3.FName as proName,t3.Fmodel as Fmodel,sum(t1.FQty) as YearInAmount from
ICStockBill t2
join ICStockBillEntry t1 on t1.FInterID = t2.FInterID
join t_icitem t3 on t3.FItemID = t1.FItemID
join ICTransactionType t5 on t2.FTranType=t5.FID
join t_StockPlace t4 on t4.FSPID = t1.FDCSPID
where t2.FTranType = '2' and (t4.FSPID = '2' or t4.FSPID = '1')
and t2.FDate >= '2024-1-1' and t2.FDate <= '2024-12-27'
) as subquery
group by proName,FModel