Below are some example SQL queries for common operations related to car manufacturers and seller companies:
- Select all manufacturers:
SELECT * FROM Manufacturer;
- Select all car models along with their manufacturers:
SELECT CarModel.*, Manufacturer.Name AS ManufacturerName FROM CarModel JOIN Manufacturer ON CarModel.ManufacturerID = Manufacturer.ManufacturerID;
- Select all seller companies:
SELECT * FROM SellerCompany;
- Select all car listings with details about the car model and seller:
SELECT CarListing.*, CarModel.Name AS ModelName, SellerCompany.Name AS SellerName FROM CarListing JOIN CarModel ON CarListing.CarModelID = CarModel.ModelID JOIN SellerCompany ON CarListing.SellerID = SellerCompany.SellerID;
- Find all car models produced by a specific manufacturer (e.g., Toyota):
SELECT CarModel.* FROM CarModel JOIN Manufacturer ON CarModel.ManufacturerID = Manufacturer.ManufacturerID WHERE Manufacturer.Name = 'Toyota';
- Find all car listings for cars with a specific condition (e.g., "Used"):
SELECT CarListing.*, CarModel.Name AS ModelName, SellerCompany.Name AS SellerName FROM CarListing JOIN CarModel ON CarListing.CarModelID = CarModel.ModelID JOIN SellerCompany ON CarListing.SellerID = SellerCompany.SellerID WHERE CarListing.Condition = 'Used';
- Calculate the average price of all listed cars:
-
SELECT AVG(Price) AS AveragePrice FROM CarListing;
- Find the newest car model by a specific manufacturer (e.g., BMW):
SELECT CarModel.* FROM CarModel JOIN Manufacturer ON CarModel.ManufacturerID = Manufacturer.ManufacturerID WHERE Manufacturer.Name = 'BMW' ORDER BY Year DESC LIMIT 1;
Click below for detailed information about the schema:
Comments
Post a Comment