There is a payment log (payments) table. Every time a payment is attempted, one row is added, and each row has the payment method (method), whether it succeeded (status: success or failed), the amount (amount), and the time. Write a single SELECT statement that computes the success rate (%) for each payment method. The success rate is the share of successful payments among all payments for that method, expressed as a percentage. The result has two columns: - method : the payment method - success_rate : the success rate (%) for that method Sort by method name in ascending order. Write your query in solution.sql, and pressing 'Run test' runs it against a real database and shows the result table.
This challenge has you write a PostgreSQL SELECT statement that computes the success rate (%) per payment method from a payment log. A table of payment records comes ready with data, and pressing 'Run test' runs your query against a real database and shows the result table. The result has two columns: one for the payment method, one for that method's success rate.
This problem is about "when you take a ratio, what you divide by can change the answer entirely." A query that counts rows and takes a ratio can look right at a glance, yet depending on the nature of the two values you divide, the result can come out blunt instead of the precise value you expected. Before trusting such a query, don't just skim the table — run it for real and watch that even the spots where a non-round ratio should appear come out as the actual value.