Reputation: 23
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
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
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