SELECT tc.country_code, (SELECT COUNT(tb.tbl_id) FROM tbl_booking tb WHERE tb.country = tc.country_code) AS total_booking, COUNT(DISTINCT tbd.booking_id) AS confirmed_booking FROM tbl_country tc LEFT JOIN tbl_booking tb ON tc.country_code = tb.country LEFT JOIN tbl_booking_details tbd ON tb.tbl_id = tbd.booking_id AND tbd.pay_status = 1 AND tbd.booking_cancle_status = 0 GROUP BY tc.country_code;
SELECT tc.country_code, (SELECT COUNT(tb.tbl_id) FROM tbl_booking tb WHERE tb.country = tc.country_code) AS total_booking,
COUNT(DISTINCT tbd.booking_id) AS confirmed_booking FROM tbl_country tc
JOIN tbl_booking tb ON tc.country_code = tb.country
JOIN tbl_booking_details tbd ON tb.tbl_id = tbd.booking_id AND tbd.pay_status = 1 AND tbd.booking_cancle_status = 0
GROUP BY tc.country_code;
======================percentage
SELECT tc.country_code, (SELECT COUNT(tb.tbl_id) FROM tbl_booking tb WHERE tb.country = tc.country_code) AS total_booking, COUNT(DISTINCT tbd.booking_id) AS confirmed_booking, COUNT(DISTINCT tbd.booking_id) * 100.0 / NULLIF((SELECT COUNT(tb.tbl_id) FROM tbl_booking tb WHERE tb.country = tc.country_code), 0) AS confirmed_percentage FROM tbl_country tc LEFT JOIN tbl_booking tb ON tc.country_code = tb.country LEFT JOIN tbl_booking_details tbd ON tb.tbl_id = tbd.booking_id AND tbd.pay_status = 1 AND tbd.booking_cancle_status = 0 GROUP BY tc.country_code;
Comments
Post a Comment