← All SQL interview questions

Successful payments by payment method

EasyGROUP BYRazorpayPayPal

A payments analyst wants to know which payment methods bring in the most money, ignoring anything that did not go through.

From payment_txns, count the successful transactions and add up their amounts for each method. Return method, txn_count and total_amount, with the highest total_amount first.

Sample data

Table: payment_txns

15 row(s) · showing first 8

txn_idINTmethodTEXTamountNUMERIC(10,2)statusTEXT
1UPI1200.00SUCCESS
2UPI450.50SUCCESS
3Card8999.00SUCCESS
4Card2300.00FAILED
5NetBanking5600.00SUCCESS
6UPI780.00FAILED
7Wallet299.00SUCCESS
8Card15400.00SUCCESS