user380603
user380603

Reputation: 173

problems with using count

I'm trying to find out what type of membership which is the type_id has with a count of cars that have this membership

Here are my tables

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;

Please help

Upvotes: 2

Views: 72

Answers (2)

Mark Byers
Mark Byers

Reputation: 838096

Use GROUP BY and COUNT:

SELECT type_id, COUNT(*)
FROM car_hire
GROUP BY type_id

Upvotes: 1

xil3
xil3

Reputation: 16439

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

Upvotes: 1

Related Questions