帮助了解 SQL 总计和总和
我有这个SQL。我不确定这是否是我需要的,但它确实选择了我需要的所有记录。我现在只需要压缩它们并计算独特日期的计数和金额即可。
select m.account_tag, m.cmcl_forecast_cleared, m.check_amount,
a.acct_id, a.acct_no, a.bank_id,
b.bank_id, b.name
from ap_master m
join accounts a on a.acct_id=m.account_tag
join banks b on b.bank_id=a.bank_id
where m.cmcl_bank_cleared is null
order by m.account_tag, m.cmcl_forecast_cleared
我只想显示四列帐户、日期、计数和总和
帐户将为 a.acct_no。
该日期将是该帐户的唯一 m.cmcl_forecast_cleared 日期
计数将是这些唯一日期 (cmcl_forecast_cleared) 的检查(记录)总数
总和将是这些唯一日期的总 check_amount (cmcl_forecast_cleared)
我希望这是可以理解的。我不确定是否需要任何分组
I have this SQL. Im not sure it is what i need, but it does select all the records i need. I just need to condense them now and total the counts and amounts for unique dates.
select m.account_tag, m.cmcl_forecast_cleared, m.check_amount,
a.acct_id, a.acct_no, a.bank_id,
b.bank_id, b.name
from ap_master m
join accounts a on a.acct_id=m.account_tag
join banks b on b.bank_id=a.bank_id
where m.cmcl_bank_cleared is null
order by m.account_tag, m.cmcl_forecast_cleared
I only want to display four columns Account, Date, Count, and sum
The account would be a.acct_no.
The date would all unique m.cmcl_forecast_cleared date for that account
The count would be total no of checks (records) for those unique dates (cmcl_forecast_cleared)
The sum would be the total check_amount for thos unique dates (cmcl_forecast_cleared)
I hope this is understandable. Im not sure if i need any grouping or not
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以根据需要按任意数量的列进行分组。
You group by as many columns as you need.