Chapter 1 Q & A
Chapter 1 Q & A
b)
SELECT ROUND(123.2345, 2),
ROUND(342.9234, -1);
Output: 123.23, 340
Explanation:
• ROUND(123.2345, 2) rounds to 2 decimal places → 123.23
• ROUND(342.9234, -1) rounds to nearest 10 → 340
d)
SELECT YEAR("1979/11/26"),
MONTH("1979/11/26"),
DAY("1979/11/26"),
MONTHNAME("1979/11/26");
Output: 1979, 11, 26, November
e)
SELECT LEFT("INDIA", 3),
RIGHT("Computer Science", 4);
Output: IND, ence
Explanation:
• First 3 characters of "INDIA" → IND
• Last 4 characters of "Computer Science" → ence
f)
SELECT MID("Informatics", 3, 4),
SUBSTR("Practices", 3);
Output: form, actices
Explanation:
• MID("Informatics", 3, 4) → from 3rd character, next 4 → form
• SUBSTR("Practices", 3) → from 3rd character to end → actices
iii. List the Product Code, Product name and price in descending order of their product name. If PName is the
same then display the data in ascending order of price.
SELECT PCode, PName, UPrice FROM Product ORDER BY PName DESC, UPrice ASC;
v. Calculate the value of the discount in the table Product as 10% of the UPrice for all those products where the
UPrice is more than 100, otherwise the discount will be 0.
UPDATE Product SET Discount = CASE WHEN UPrice > 100 THEN UPrice * 0.10 ELSE 0 END;
vi. Increase the price by 12% for all the products manufactured by Dove:
UPDATE Product SET UPrice = UPrice * 1.12 WHERE Manufacturer = 'Dove';
4. Using the CARSHOWROOM database given in the chapter, write the SQL queries for the following:
a) Add a new column Discount in the INVENTORY table.
ALTER TABLE INVENTORY ADD Discount DECIMAL(5,2);
c) Display the name of the costliest car with fuel type 'Petrol'
SELECT CarName FROM INVENTORY WHERE FuelType = 'Petrol' ORDER BY Price DESC LIMIT 1;