本文介绍了在单个查询中更新2列.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是维卡什.

假设我有一个数据表,如下所示:

EmpID等级
1 A
2 B
3 B
4 A
5 B
6 A
7 A
8 A

现在,我想在一个更新查询中将所有A设为B,将所有B设为A.

该怎么办呢?

请帮忙.

在此先感谢.

hello, this is vikash.

Say I have a table with data as follows :

EmpID Grade
1 A
2 B
3 B
4 A
5 B
6 A
7 A
8 A

now i want to make all A as B and all B as A in a single update query.

How can this be done.

Please help.

Thanks in Advance.

推荐答案

UPDATE [grades]
   SET [grade] = case when [grade] = 'A' then 'B'
                    else 'A'
                    end



干杯.



Cheers.


UPDATE titles
       SET price =
                 CASE
                   WHEN (price < 5.0 AND ytd_sales > 999.99)
                                   THEN price * 1.25
                   WHEN (price < 5.0 AND ytd_sales < 1000.00)
                                   THEN price * 1.15
                   WHEN (price > 4.99 AND ytd_sales > 999.99)
                                   THEN price * 1.2
                   ELSE price
                 END




您的情况要简单得多.




your case is much simpler.


这篇关于在单个查询中更新2列.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 17:21