Q: Region is a mix of abbreviations and full names. Fix up the remaining regions by converting the full names to their corresponding abbreviations (e.g., South Australia -> SA). Can you work out how to do this using a single query?
区域是由缩写和全名混合而成的。通过将全名转换为相应的缩写 (例如,South Australia -> SA) 来修复其余区域。你能想出如何使用一个单一的查询来做到这一点吗?
如果运行以上语句将会出现一个错误,
Cannot insert the value NULL into column 'region', table 'AmazonOrders.dbo.Addresses'; column does not allow nulls. UPDATE fails.
这是因为先前建表时设置 region 的内容不能为空
注意:
CASE WHEN THEN ELSE END
可以不写else但是一定要有end ,没有else如果不满足条件会以null填充
解决方法:
为使其余值保持不变,加入 ELSE column 语句
本例中为 ELSE region:
查看修改结果:
SELECT column FROM Table