Question:

Shalini, who works as a database designer in the hotel industry, has created a table named Guest to keep track of guest details as shown below:

Table : Guest

GuestIDGuestNameRoomNumberCheckInDateCharges
G101Harish1012025-04-033000
G102Sunita1012025-04-033000
G103Ramesh1022025-05-045000
G104Bhumika1032025-06-023500

Write a suitable SQL query for the following:

I. Display last 3 characters of guest name in upper case.

II. Display the name of the guest along with the day name of check-in date.

III. Display the remainder when charges are divided by 1000.

IV. Extract and display three characters, starting from the second character, of each guest name.

Show Hint

Use RIGHT with UPPER, DAYNAME for the weekday, MOD for the remainder and MID or SUBSTR starting at position 2 with length 3.
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Read the table:
The table Guest has 4 rows. GuestName holds text, CheckInDate holds a date and Charges holds a number.
Each part needs one single-row function applied to a column.

Step 2: Part (I) - last 3 characters in upper case:
RIGHT(string, n) gives the last n characters. UPPER() changes them to capital letters. We put RIGHT inside UPPER.
SELECT UPPER(RIGHT(GuestName, 3)) FROM Guest;

Output: ISH, ITA, ESH, IKA.

Step 3: Part (II) - name with the day name of check-in date:
DAYNAME(date) gives the weekday as a word.
SELECT GuestName, DAYNAME(CheckInDate) FROM Guest;

Output: Harish - Thursday, Sunita - Thursday, Ramesh - Sunday, Bhumika - Monday.

Step 4: Part (III) - remainder of charges divided by 1000:
MOD(a, b) gives the remainder of a divided by b.
SELECT MOD(Charges, 1000) FROM Guest;

3000 gives 0, 3000 gives 0, 5000 gives 0 and 3500 gives 500.

Step 5: Part (IV) - three characters from the second character:
MID(string, start, length) or SUBSTR(string, start, length) starts counting at position 1. We start at 2 and take 3 characters.
SELECT MID(GuestName, 2, 3) FROM Guest;

Harish gives ari, Sunita gives uni, Ramesh gives ame and Bhumika gives hum.

Final Answer:
I. SELECT UPPER(RIGHT(GuestName, 3)) FROM Guest;
II. SELECT GuestName, DAYNAME(CheckInDate) FROM Guest;
III. SELECT MOD(Charges, 1000) FROM Guest;
IV. SELECT MID(GuestName, 2, 3) FROM Guest;
Was this answer helpful?
0
0

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

View More Questions