MySQL Exercise No:3
Consider the following tables CARHUB and CUSTOMER and Write SQL commands for the statements (i) to (iii)
and give output for SQL queries (iv) and (v).
Table : CARHUB
Vcode Vehiclename Make Color Capacity Charges
100 Innova Toyota White 7 15
102 SX4 Suzuki Blue 4 14
104 C Class Mercedes Red 4 35
105 A-Star Suzuki White 3 14
108 Indigo Tata Silver 3 12
Table : CUSTOMER
CCode CName Vcode
1 Hemant Sahu 101
2 Raj Lal 108
3 Feroza Shah 105
4 Ketan Dhal 104
i. To display the names of all white colored vehicles.
ii. To display name of vehicle, make and capacity of vehicles in ascending order of their seating
capacity.
iii. To display the customer name and the corresponding name of the vehicle hired by them.
iv. SELECT MAX(charges), MIN(charges) FROM CARHUB;
v. SELECT COUNT(*), Make FROM CARHUB GROUP BY MAKE;
Answers:
i. SELECT Vehiclename FROM CARHUB WHERE Color=’White’;
ii. SELECT Vehiclename, Make, Capacity FROM CARHUB ORDER BY Capacity;
iii. SELECT CName, Vehiclename FROM CUSTOMER, CARHUB WHERE
[Link]=[Link];
iv.
MAX(Charges) MIN(Charges)
35 12
v.
COUNT(*) MAKE
1 Toyota
2 Suzuki
1 Mercedes
1 Tata