Question:medium

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

Solution and Explanation

Step 1: Pick the function for each demand:
Last characters of a string: RIGHT. Capital letters: UPPER. Weekday word of a date: DAYNAME.
Remainder: MOD. A piece from the middle of a string: MID or SUBSTR.

Step 2: Part (I):
First RIGHT cuts the last 3 letters from each name: ish, ita, esh, ika. Then UPPER makes them capital.
The function in the brackets runs first, so RIGHT is written inside UPPER.
SELECT UPPER(RIGHT(GuestName, 3)) FROM Guest;

Result rows: ISH, ITA, ESH, IKA.

Step 3: Part (II):
We need two columns, the name and the weekday. The weekday comes from the date 2025-04-03, 2025-04-03, 2025-05-04 and 2025-06-02.
SELECT GuestName, DAYNAME(CheckInDate) FROM Guest;

3 April 2025 was a Thursday, 4 May 2025 was a Sunday and 2 June 2025 was a Monday.
Result rows: Harish Thursday, Sunita Thursday, Ramesh Sunday, Bhumika Monday.

Step 4: Part (III):
1000 goes into 3000 exactly three times, so nothing is left. 5000 is exactly five times 1000.
3500 is three times 1000 plus 500, so the remainder is 500.
SELECT MOD(Charges, 1000) FROM Guest;

Result rows: 0, 0, 0, 500. The operator form Charges % 1000 gives the same values.

Step 5: Part (IV):
In SQL the first character is at position 1. So position 2 is the second letter. We take 3 letters from there.
SELECT SUBSTR(GuestName, 2, 3) FROM Guest;

Harish: letters 2 to 4 are a, r, i. Sunita: u, n, i. Ramesh: a, m, e. Bhumika: h, u, m.

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 SUBSTR(GuestName, 2, 3) FROM Guest;
Was this answer helpful?
0