CREATE TABLE my_table ( bank_account, bank_id, amount ) AS
SELECT 123, 600, 1500 FROM DUAL UNION ALL
SELECT 123, 600, 2500 FROM DUAL UNION ALL
SELECT 123, 600, 3500 FROM DUAL UNION ALL
SELECT 123, 700, 500 FROM DUAL UNION ALL
SELECT 123, 700, 1000 FROM DUAL UNION ALL
SELECT 456, 800, 2000 FROM DUAL UNION ALL
SELECT 456, 900, 2000 FROM DUAL UNION ALL
SELECT 456, 900, 4000 FROM DUAL;
I need to write the SQL code where the result would look like this:
Where:
total_amount - the sum of all transactions bank_account made in specific bank_id
number_of_transactions - number of transactions made by bank_account in specific bank_id
total_num_trans - total number of transactions made by bank_account
total_am_trans - total amount of transactions made by bank_account
I've only managed to get some of the results I need, but can't get them all. This is with what I've started:
SELECT t.bank_account
, t.bank_id
, count(*) number_of_transactions
, sum(t.amount) total_amount
FROM my_table t
GROUP BY t.bank_account
, t.bank_id
ORDER BY t.bank_account
Thanks.
