SQL Assignment Saurav
SQL Assignment Saurav
SQL Assignment Saurav
CODE:-
CREATE DATABASE sql_assignment;
USE sql_assignment;
INSERT INTO
Bike203(ModelID,Manufacturer,M_Year,Price,Sales,Showroom_ID)
VALUES
(101,"Bajaj",2010,95000,50,1),
(101,"Bajaj",2012,90000,30,2),
(102,"Bajaj",2020,130000,60,3),
(201,"TVS",1995,105000,70,3),
(201,"TVS",1995,105000,70,4),
(202,"TVS",2020,125000,20,5),
(301,"Royal Enfield",1960,145000,45,1),
(301,"Royal Enfield",1960,145000,45,5),
(302,"Royal Enfield",2000,180000,70,2),
(401,"Hero",2000,65000,80,1),
(401,"Hero",2000,65000,80,2),
(402,"Hero",2024,55000,90,3),
(402,"Hero",2023,55000,90,4),
(501,"Yamaha",2006,115000,10,1),
(502,"Yamaha",2020,140000,25,3);
CODE:-
SELECT Manufacturer, AVG(Price) FROM Bike203
GROUP BY Manufacturer;
CODE:-
CODE:-
SELECT Manufacturer, SUM(sales) FROM Bike203
JOIN Showroom203
ON Bike203.Showroom_ID = Showroom203.Showroom_ID
GROUP BY Manufacturer;
CODE:-
SELECT Manufacturer203.Model_Name, Bike203.Manufacturer, Bike203.Price
FROM Bike203
JOIN Showroom203
ON Bike203.Showroom_ID = Showroom203.Showroom_ID
JOIN Manufacturer203
ON Bike203.ModelID = Manufacturer203.Model_ID
WHERE Bike203.Price = (SELECT MAX(Price) FROM Bike203);
CODE:-
SELECT Manufacturer203.Model_Name, Bike203.Manufacturer, Bike203.Price
FROM Bike203
JOIN Manufacturer203
ON Bike203.ModelID = Manufacturer203.Model_ID
WHERE Bike203.Price > (SELECT AVG(Price) FROM Bike203);
CODE:-
SELECT DISTINCT Showroom203.Showroom_Name, Bike203.Manufacturer
FROM Bike203
JOIN Showroom203
ON Bike203.Showroom_ID = Showroom203.Showroom_ID
WHERE Bike203.Manufacturer = 'TVS';
CODE:-
SELECT Showroom203.Showroom_Name, AVG(Bike203.Price) AS Average_Price
FROM Bike203
JOIN Showroom203
ON Bike203.Showroom_ID = Showroom203.Showroom_ID
GROUP BY Showroom203.Showroom_Name;
CODE:-
SELECT Model_Name, Manufacturing_Place
FROM Manufacturer203
WHERE Manufacturing_Place = 'Tamil_Nadu';
CODE:-
SELECT DISTINCT Showroom203.Showroom_Name, Manufacturer203.Model_Name,
Manufacturer203.Engine_CC
FROM Bike203
JOIN Manufacturer203
ON Bike203.ModelID = Manufacturer203.Model_ID
JOIN Showroom203
ON Bike203.Showroom_ID = Showroom203.Showroom_ID
WHERE Manufacturer203.Engine_CC > 200;
CODE:-
SELECT Manufacturer203.Model_Name, SUM(Bike203.Sales) AS Total_Sales
FROM Bike203
JOIN Manufacturer203
ON Bike203.ModelID = Manufacturer203.Model_ID
GROUP BY Manufacturer203.Model_Name;
CODE:-
SELECT Showroom203.Showroom_Name, Bike203.Price
FROM Bike203
JOIN Showroom203
ON Bike203.Showroom_ID = Showroom203.Showroom_ID
WHERE Bike203.Price = (SELECT MIN(Price) FROM Bike203);
CODE:-
SELECT Manufacturer203.Manufacturing_Place, Manufacturer203.Model_Name,
AVG(Manufacturer203.Engine_CC) AS Avg_Engine_CC
FROM Manufacturer203
GROUP BY Manufacturer203.Manufacturing_Place, Manufacturer203.Model_Name;
CODE:-
SELECT Manufacturer203.Model_Name, Manufacturer203.Engine_CC, Bike203.Sales
FROM Bike203
JOIN Manufacturer203 ON Bike203.ModelID = Manufacturer203.Model_ID
WHERE Manufacturer203.Engine_CC > 150 AND Bike203.Sales > 50;
CODE:-
SELECT Showroom203.Showroom_Name, AVG(Bike203.Price) AS Avg_Price
FROM Bike203
JOIN Showroom203
ON Bike203.Showroom_ID = Showroom203.Showroom_ID
GROUP BY Showroom203.Showroom_Name;