SQL CASE Expression
The SQL CASE Expression
C언어의 case와 동일한 기능
CASE Syntax
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;
SQL CASE Examples
SELECT OrderID, Quantity,
CASE
WHEN Quantity > 30 THEN 'The qunatity is greater than 30'
WHEN Quantity = 30 THEN 'The quantity is 30'
ELSE 'The quantity is under 30'
END AS QuantityText
FROM OrderDetails;
SELECT CustomerName, City, Country
FROM Customers
ORDER BY (
CASE
WHEN City IS NULL THEN Country
ELSE City
END
);
'Computer Science > Database' 카테고리의 다른 글
W3Schools SQL | #34 SQL STORED PROCEDURES - SQL SERVER (0) | 2022.10.29 |
---|---|
W3Schools SQL | #33 SQL NULL 함수 (0) | 2022.10.29 |
W3Schools SQL | #31 SQL INSERT INTO SELECT 구문 (0) | 2022.10.29 |
W3Schools SQL | #29 SQL ANY ALL 연산자 (0) | 2022.10.28 |
W3Schools SQL | #28 SQL EXISTS 연산자 (0) | 2022.10.28 |