HomeInterview QuestionsSql, Case, Conditional Display

If a column represents a transaction, how do you display the transaction type when the value equals 'withdrawal' or 'deposit'?

🟡 Medium Conceptual Junior level
1 Times asked
Mar 2026 Last seen
Mar 2026 First seen

💡 Model Answer

You can use a CASE expression to map numeric or coded values to human-readable labels. For example, if the column "txn_type" stores 1 for withdrawal and 2 for deposit, you can write:

SELECT

txn_id,

CASE txn_type

WHEN 1 THEN 'Withdrawal'
WHEN 2 THEN 'Deposit'
ELSE 'Other'

END AS transaction_type

FROM transactions;

This expression evaluates the value of txn_type for each row and returns the corresponding string. In MySQL you could also use IF(txn_type = 1, 'Withdrawal', 'Deposit') if only two options exist. The CASE construct is ANSI‑standard and works across most RDBMS.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500