hEY ALL
i have a table that shows transactions and their status. How can i create a column that shows the total of transactions that are completed,rejected,declined and the grand total of all on a different column
for example i am looking something like this
Completed 100
Rejected 50
Declined 20
Total 170
In 3 different rows..
The table fields are something like this.
transaction_id
status_id,
date
transaction_number
Assuming the textual status you mention in your desired output corresponds to the
status_idcolumn in your table, you could use something like:This works for SQL Server 2000 and newer – not sure if other RDBMS have the exact same syntax… (unfortunately, you didn’t mention what system you’re using…)
The
WITH ROLLUPwill cause an extra line to be added to your result with astatus_idof NULL – this is the total of all counts combined.You didn’t mention how to “translate” the
status_idinto a textual description – that could be added if you provide the necessary info….