您正确地确定加入有助于获取每位客户的预订总数,因此
DROP TABLE IF EXISTS BOOKINGS,drivers;
create table Bookings (booking_id int, driver_id int, customer_id varchar(3));
create table Drivers (driver_id int, name varchar(3));
insert into bookings values
(1,1,1),(2,1,1),(3,2,1),(4,2,1),(5,3,1),
(6,1,2),(7,2,1);
insert into drivers values
(1,'aaa'),(2,'bbb');
select b.driver_id,d.name,b.customer_id,count(*) bcount,scount, count(*) / scount * 100 percent
from bookings b
join (select customer_id,count(*) scount from bookings group by customer_id) s
on s.customer_id = b.customer_id
join drivers d on d.driver_id = b.driver_id
group by driver_id,d.name,customer_id having count(*) / scount * 100 >= 50;
+-----------+------+-------------+--------+--------+----------+
| driver_id | name | customer_id | bcount | scount | percent |
+-----------+------+-------------+--------+--------+----------+
| 1 | aaa | 2 | 1 | 1 | 100.0000 |
| 2 | bbb | 1 | 3 | 6 | 50.0000 |
+-----------+------+-------------+--------+--------+----------+
2 rows in set (0.002 sec)
测试 50% 比测试 60% 更容易 - 不要忘记根据您的要求进行更改。