使用日期列和按多个列分组来计算年初至今?

时间:2019-11-08 20:05:21

标签: sql group-by sum zoho

我有一个带有列的表: enter image description here

我正在尝试计算= (Accounts Payable/YTD_Vendor_Expenses)*Number of days in Period天后的应付帐款。

我正在尝试以下查询,但似乎不起作用(我正在ZOHO Analytics中运行查询):

SELECT groupkey,
`Total Accounts Payable`,
Report_Month,
`Total Income`,
month(`Report_Month`) * 30 as `Number of Days in Period`,
YTD(sum(`Vendor Expenses`),`Report_Month`) as `YTD_Vendor Expenses`,
(sum(`Total Accounts Payable`) / YTD(sum("Vendor Expenses"),"Report_Month") * (month(`Report_Month`) * 30) 
FROM  apd_table  
GROUP BY `groupkey`,
`Report_Month`,
`Total Accounts Payable`,
`Total Income`

我正在寻找如下输出: enter image description here

请帮助我。谢谢。

0 个答案:

没有答案