tags:

views:

35

answers:

2

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

+1  A: 
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
xil3
Thank you sooooo much!!! it worked! I'm very new to sql so i'm still trying to understand it. I triedSELECT Car_id, COUNT(type_description) as "number of cars"FROM car_type,car_hireswhere car_idGROUP BY type_descriptionwhich came up with something but didn't do the trick ;-(Is there a website that explains queries in full?
+1  A: 

Use GROUP BY and COUNT:

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