learncode
learncode

Reputation: 23

Query to display the % of the failure rate

I have written this query to get my data, and all the data is fine.

I have one column which has either Pass Or Fail. I want to calculate the % of number of bookings that failed, and output it in a single value.

I will have to write another query to show that one number.

Upvotes: 0

Views: 487

Answers (2)

Ullas
Ullas

Reputation: 11556

Query

select 
  concat(
    cast(
      (
        sum(case when t.Decision = 'Fail' then 1 else 0 end) / count(*)) * 100 
      as varchar(3)
  ), '%') as `fail rate`
from
(
  select ........
  case ........ end as Decision
)t;

Upvotes: 0

shawnt00
shawnt00

Reputation: 17935

Perhaps this? You didn't really offer much to go on:

SELECT
    SUM(CASE
        WHEN trip_rating.rating <= 3 OR
           TIMESTAMPDIFF(MINUTE, booking_activity.activity_time, booking.pick_up_time) < 0 
    THEN 1.00 ELSE NULL END
    ) / COUNT(*)
FROM ...

Upvotes: 1

Related Questions