Page 11 - IPP-12-2024
P. 11
Ans. (a) (i) 20
(ii) Y2014 Y2015 Y2016 Y2017
Kinshuk 200.9 22000 70000 70000
Ankit 30000.0 30000 100000 80000
(b) print (Sales.loc["Maith", "Ankit"], [2015, 2017])
sum_sales = df[['Y2015', 'Y2017']].sum()
Section E
33. Write suitable SQL queries for the following: [5]
(i) Display the substring “good” from string “good morning”.
(ii) Display the starting position of the occurrence of the string “morning” in the given string “good morning”.
(iii) Display the name of the day of your birth date.
(iv) Display the round-off value 72.835 to two decimal places.
(v) Display the exponent for 2 raised to the power of 3.
Ans. (i) select left("good morning",4);
Or
SELECT SUBSTRING('good morning', 1, 4) AS 'Substring';
(ii) select Instr("good morning", "morning");
Or
SELECT INSTR('good morning', 'morning') AS 'StartPosition';
(iii) select dayname('1970-10-02');
(iv) select round(72.835,2);
(v) select power(2,3); or select pow(2,3);
Or
Explain the following SQL functions using suitable examples.
(i) LCASE() (ii) NOW()
(iii) RTRIM() (iv) MONTHNAME()
(v) MOD()
(i) LCASE() function
• The LCASE() function is used to convert a string to lowercase letters.
Example:
SELECT LCASE('Hello World') AS 'LowercaseString';
(ii) NOW() function
• The NOW() function is used to get the current date and time from the database server.
Example:
SELECT NOW() AS 'CurrentDateTime';
(iii) RTRIM() function
• The RTRIM() function is used to remove trailing spaces from a string.
Example:
SELECT RTRIM(' Trim This ') AS 'TrimmedString';
(iv) MONTHNAME() function
• The MONTHNAME() function is used to get the name of a month from the given date.
Example:
SELECT MONTHNAME('2023-08-21') AS 'MonthName';
(v) MOD() function
• The MOD() function is used to calculate the remainder when one number is divided by another.
Example:
SELECT MOD(15, 4) AS 'Remainder';
Appendices A.33