database schema and SQL Query for Car Manufacturers and selller

 Below are some example SQL queries for common operations related to car manufacturers and seller companies:



  1. Select all manufacturers:
  2. SELECT * FROM Manufacturer;
  3. Select all car models along with their manufacturers:
  4. SELECT CarModel.*, Manufacturer.Name AS ManufacturerName FROM CarModel JOIN Manufacturer ON CarModel.ManufacturerID = Manufacturer.ManufacturerID;
  5. Select all seller companies:
  6. SELECT * FROM SellerCompany;
  7. Select all car listings with details about the car model and seller:
  8. 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;
  9. Find all car models produced by a specific manufacturer (e.g., Toyota):
  10. SELECT CarModel.* FROM CarModel JOIN Manufacturer ON CarModel.ManufacturerID = Manufacturer.ManufacturerID WHERE Manufacturer.Name = 'Toyota';
  11. Find all car listings for cars with a specific condition (e.g., "Used"):
  12. 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';
  13. Calculate the average price of all listed cars:
  14. SELECT AVG(Price) AS AveragePrice FROM CarListing;
  15. Find the newest car model by a specific manufacturer (e.g., BMW):
  16. 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