Lab - 2 SQL - Assignment - 2: Section1 - Mayank Smart Vehicle Database
Lab - 2 SQL - Assignment - 2: Section1 - Mayank Smart Vehicle Database
7-Sept-2021
IT214 Database Management System, Autumn’2021; Instructor: minal_bhise@daiict, TA: mayank@daiict
Engine_Spec
Vehicle_types Engine_id
VType_id Max_power
Gearbox_details V_name No_of_cylinders
G_id V_model Fuel_type
G_type V_type Fuel_tank_size
No_of_gears V_colour Max_speed
City_mileage
Highway_mileage
Engine_id
Gearbox_id
a. Use of group by.
select count(*), reg_state from vehicle_details group by reg_state;
But it shows only the first record, not all the v_names having similar speeds.
SELECT max(max_speed)
FROM sv_db.engine_spec;
Step2.
Write a subquery as a part of the main query to get the ID.
Step3.
Write a subquery as a part of the main query having joins.
Step2.
Join the above query with another table.
Step2.
Use VIEW as a table.
select vehicle_types.v_name, max_speed from
vehicle_types
join
MaxSpeed_Engine_VIEW
on
vehicle_types.engine_id = engine_id;
b. Auto-updates of VIEWs.
CREATE OR REPLACE VIEW AVG_Speed_VIEW as
Select AVG(max_speed) from
sv_db.engine_spec;
After creating a view, update the max_speed column by adding new records or
updating existing records, and see if the average gets updated or not.
Check if Engine_spec has new record or not. As it’s a simple view, it will update the
original table.
f. Create & Update below given Partial VIEW of a Table which donot
include PK attributes.