[英]How to aggregate data by SQL?
我不是SQL開發人員,但我需要提出請求以抽樣上個月的帳戶變動,並按客戶國家/地區匯總信息。
我只能創建一個示例數據庫,但不知道下一步該怎么做。
您的問題尚不清楚,但是您將需要使用諸如SUM或COUNT之類的聚合函數以及根據需要使用GROUP BY。
以下是按國家/地區划分的交易金額總和。
select country, sum(transactions.amount) as TOTAL_AMT
from clients as clients
inner join accounts as accounts
on accounts.client_id = clients.client_id
inner join transactions as transactions
on transactions.sender_account_id = accounts.account_id
group by country;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.