English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
CASE命令用于根据条件创建不同的输出。
以下SQL经历了几种条件,并在满足指定条件时返回一个值:
SELECT OrderID, Quantity, CASE 当 Quantity > 30 然后 "The quantity is greater than 30" WHEN Quantity = 30 THEN "The quantity is 30" ELSE "The quantity is under 30" END FROM OrderDetails;
The following SQL will sort customers by city (City). However, if City is NULL, it will sort by country/Region (Country) Sorting:
SELECT CustomerName, City, Country FROM Customers ORDER BY (CASE WHEN City IS NULL THEN Country ELSE City END);