Question:medium

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

Solution and Explanation

Step 1: Ask what each part changes:
Part I trims a date-time to a date. Part II changes the letter case. Part III cuts a piece of text.
Part IV cleans spaces. Part V calculates one number from many rows.

Step 2: Part I:
The value '2026-01-01 10:10:10' has a date and a time. DATE() returns only 2026-01-01.
SELECT DATE('2026-01-01 10:10:10');


Step 3: Part II:
The column is Cust_Name in the table Customer. The function that gives small letters is LOWER (the function LCASE also works).
SELECT LOWER(Cust_Name) FROM Customer;


Step 4: Part III:
We want 4 characters from the start of City_Name. SUBSTR with start 1 and length 4 does this.
SELECT SUBSTR(City_Name, 1, 4) FROM Location;

For a city such as Mumbai the result is Mumb. LEFT(City_Name, 4) is the other correct form.

Step 5: Part IV:
Leading means at the beginning. The function for removing the left spaces is LTRIM.
SELECT LTRIM(CITY) FROM EVENT;

For ' Delhi' the output is 'Delhi'.

Step 6: Part V:
The mean of a column is found by AVG. The query reads the whole Salary column and returns one value.
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 SUBSTR(City_Name, 1, 4) FROM Location;
IV. SELECT LTRIM(CITY) FROM EVENT;
V. SELECT AVG(Salary) FROM Employees;
Was this answer helpful?
0