2

テーブルには data.like this one があります

ID      NAME
1   Apple
2   Apple
3   Apple
4   orange
5   orange
6   orange
7   Apple
8   Apple
9   Apple
10  orange
11  orange
12  orange

データは 1000 回を超える場合があります。現在、リンゴをオレンジに、オレンジをリンゴに交換/変更/更新する必要があります。

4

2 に答える 2

7

これはcaseupdateステートメント内で次のように行います。

update t
    set name = (case when name = 'Apple' then 'Orange'
                     when name = 'Orange' then 'Apple'
                end)
    where name in ('Apple', 'Orange');

これは標準 SQL であり、MySQL と Oracle の両方で機能します。

実際に名前を変更する必要はなく、 で交換するだけの場合selectは、クエリでロジックを実行します。

select (case when name = 'Apple' then 'Orange'
             when name = 'Orange' then 'Apple'
             else name
        end) as name
from t;
于 2013-08-21T11:30:51.490 に答える
0
update  YourTable
set     name = 
        case name
        when 'Apple' then 'Orange'
        when 'Orange' then 'Apple'
        end 
 where  name in ('Apple', 'Orange')
于 2013-08-21T11:30:24.413 に答える