计算这两天的 id SQL

Counting id for both days SQL

有人能帮帮我吗?

任务是找出这两天搭车的司机的搭车次数

create table rides 
(
    ride_id int, 
    driver_id int,
    ride_in_kms int, 
    ride_fare float, 
    ride_date date
);

insert into rides values (1, 1, 3, 4.45, "2016-05-16");
insert into rides values (2, 1, 4, 8.46, "2016-05-16");
insert into rides values (3, 2, 6, 11.9, "2016-05-16");
insert into rides values (4, 3, 3, 6.76, "2016-05-16");
insert into rides values (5, 2, 6, 13.55, "2016-05-16");
insert into rides values (6, 4, 3, 4.91, "2016-05-20");
insert into rides values (7, 1, 7, 16.77, "2016-05-20");
insert into rides values (8, 3, 9, 16.18, "2016-05-20");
insert into rides values (9, 2, 3, 6.07, "2016-05-20");
insert into rides values (10, 4, 4, 6.25, "2016-05-20");

输出:

driver_id  rides
--------------
1  3
2  3
3  2

试试下面的方法

select driver_id,count(*) as cnt
from
rides
group by driver_id
having count(distinct ride_date) > 1
select driver_id ,count( ride_id) as rides
from rides group by driver_id having  driver_id in 
(select driver_id from rides
where ride_date ="2016-05-16" and driver_id in
(select driver_id from rides
 where ride_date="2016-05-20")) ;