I have a table with various columns in it and I want to produce a summary of whats in the table.
So say I have a Transactions table like
Customer, --name of the customer
Bank Name, --name of the bank the transaction took place
Balance, --current balance at the time of the transaction
Deposited, -- amount deposited
Withdrawn, -- amount withdrawn
Declined -- amount declined
and I want query that will count records based on criteria. So I would like to group by each customer,
Count of withdrawals
Count of Deposits
Count of where the withdrawn = balance, -- gives me the number of trans where the customer withdrew everything
Count of where the Deposited = balance, -- gives me the number of trans where the customer doubled their balance
Count of where Declined > 0
Percentage of monies withdrawn in terms of balance -- % of monies withdrawn in terms of balance
So my output would look something like this..
Customer, Bank, Withdrawals, Deposits, Total withdrawal, Balance Doubled, Declined Trans, % Withdrawn
ok.. I hope its not to complex and you get the picture.
So I want to do this using nicely structured SQL and best practice and the only way I can see is that I have a heap of select sub queries... I tried to use count with an expression in a group by but cant get it to work...
can anyone advise please...