SQL Keyword CASE

The BETWEEN keyword is used to create outputs based on conditions.

  • It is similar to a SWITCH statement in any of the programming languages.

The below SQL returns a message based on the order quantity, three different messages based on whether the quantity is more, less, or equal to 30.

Run this on IDE

SELECT order_id, quantity,
CASE
    WHEN quantity > 30 THEN "The quantity is greater than 30."
    WHEN quantity = 30 THEN "The quantity is equal to 30."
    ELSE "The quantity is less than 30."
END
FROM order_details;

Related Links