Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在我的SQL中做一些case语句。下面的示例显示了我想要做的事情。
例子
case WHEN p = 1 THEN 'SOMETHING' WHEN p = 1 AND q = 1 THEN 'SOMETHING ELSE'
在这里,CASE返回第一个评估为 true 的WHEN子句的结果。在此示例中,第一个和第二个WHEN 条件为真,但返回第 一个条件的结果。
CASE总是按顺序执行。只需更改WHEN子句的顺序即可获得所需的内容:
CASE
WHEN
case WHEN p = 1 AND q = 1 THEN 'SOMETHING ELSE' WHEN p = 1 THEN 'SOMETHING' end