我正在尝试找出type_id拥有的会员资格类型以及拥有此会员资格的汽车数量
这是我的表格
create table car_hire
(car_id char (5) primary key not null,
car_reg varchar (15) not null,
car_make varchar (20) not null,
car_model varchar (20) not null,
car_year date not null,
type_id char (5) not null)
engine=innodb;
create table car_type
(type_id char(4) primary key not null,
type_decription varchar (15) not null,
Hire_cost int (5) not null)
ENGINE=InnoDB;
请帮忙
答案 0 :(得分:1)
select t.type_id, count(*)
from car_type t left join car_hire h on t.type_id = h.type_id
group by t.type_id
答案 1 :(得分:1)
使用GROUP BY和COUNT:
SELECT type_id, COUNT(*)
FROM car_hire
GROUP BY type_id