MySQL CASE WHEN With Count Function Example

21-Jan-2022

.

Admin

Hello Friends,

This article will give you example of MySQL case when with count function example. I explained simply about case when with count in SQL query. This tutorial will give you simple how to use count function in case statement in MySQL.

In this post, You'll learn count function in case statement in MySQL example. i will show you use of can we use count function in case statement MySQL.

Here i will give you many example for count function in case statement example in MySQL.

So let's see bellow solution:

Table: user_payments


Solution SQL Query:

SELECT

COUNT(CASE

WHEN status = "1"

THEN 1

ELSE NULL

END) AS total_paid_payment,

COUNT(CASE

WHEN status = "0"

THEN 1

ELSE NULL

END) AS total_fail_payment

FROM `user_payments`

Output:

I hope it will help you...

#MySQL