Question:

Write suitable SQL query for the following:

I. To display only the date part from the date/time expression '2026-01-01 10:10:10'

II. To convert all customer names from the Cust_Name column to lowercase in the Customer table.

III. To extract the first 4 characters from the City_Name column in Location table.

IV. To display the name of the city from the CITY column in EVENT table, after removing leading spaces.

V. To find the average salary from Salary column in Employees table.

Show Hint

Use DATE(), LOWER(), LEFT() or SUBSTR(), LTRIM() and AVG() for the five parts.
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Match each part with an SQL function:
Date part of a date-time value: DATE(). Lower case: LOWER(). First characters of a string: LEFT().
Remove spaces on the left: LTRIM(). Average: AVG().

Step 2: Part I - date part only:
DATE() keeps the date and drops the time. No table is needed because the value is given.
SELECT DATE('2026-01-01 10:10:10');

Output: 2026-01-01

Step 3: Part II - customer names in lower case:
LOWER() changes every capital letter in the text to a small letter.
SELECT LOWER(Cust_Name) FROM Customer;


Step 4: Part III - first 4 characters of the city name:
LEFT(text, n) returns the first n characters.
SELECT LEFT(City_Name, 4) FROM Location;

SUBSTR(City_Name, 1, 4) gives the same result.

Step 5: Part IV - remove leading spaces:
LTRIM() removes the spaces at the start (left side) of the text. RTRIM() would remove the spaces at the end.
SELECT LTRIM(CITY) FROM EVENT;


Step 6: Part V - average salary:
AVG() is an aggregate function. It adds all values of the column and divides by their count. NULL values are ignored.
SELECT AVG(Salary) FROM Employees;


Final Answer:
I. SELECT DATE('2026-01-01 10:10:10');
II. SELECT LOWER(Cust_Name) FROM Customer;
III. SELECT LEFT(City_Name, 4) FROM Location;
IV. SELECT LTRIM(CITY) FROM EVENT;
V. SELECT AVG(Salary) FROM Employees;
Was this answer helpful?
0
0

Top CBSE CLASS XII Text Date and Math Functions in MySQL Questions

View More Questions