Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query selection help need

I have a table which has column called payment_txn_status

I have to write a query which shows distinct status code with their respective count.

My current query which is as below gives me only distinct status code but how to get count for each individual status code

select distinct  payment_txn_status FROM  tpayment_txn
like image 898
Vikramsinh Shinde Avatar asked Dec 05 '25 11:12

Vikramsinh Shinde


1 Answers

Use a GROUP BY and a COUNT:

SELECT payment_txn_status, COUNT(*) AS num
FROM tpayment_txn
GROUP BY payment_txn_status
like image 137
Ben Lee Avatar answered Dec 07 '25 03:12

Ben Lee