I have the following question:
For each city display the number of clients who only rented cars of type 'Toyota' or 'BMW' and never rented 'Mercedes'
The tables are as follows:
Car [CarId int, type varchar(30)]
Client [ClientId int, CityId int, Name varchar(30)]
City [CityId int, CityName varchar(30)]
Rent [CarId int, ClientId int, days_number int]
I don't know how would I formulate this query I tried hard but nothing worked until now.
Declare @count1 int, @count2 int
Select @count1 = Count(*)
From Client inner join Rent
on Client.ClientId = Rent.ClientId
inner join Car
on Car.CarId = Rent.CarId
Where Car.type In( 'Toyota','BMW')
--except
Select @count2 = Count(*)
From Client inner join Rent
on Client.ClientId = Rent.ClientId
inner join Car
on Car.CarId = Rent.CarId
Where Car.type = 'Merccedes'
Select (@count1 - @count2)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments