0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SQLによる匿名加工サンプル

Last updated at Posted at 2023-03-24

SQLにおいて匿名加工を行う場合のサンプル

匿名加工の手法については
個人情報保護委員会のガイドラインが参考になる。
https://www.ppc.go.jp/personalinfo/legal/

1.個人識別符号(ID系の情報)の置き換え

--Mysql
select sha2(concat([columname],'soltkey'),256) form [tablename]:

--Mysql(例)
mysql> select '123456',sha2(concat('123456','moji'),256) as sha2 from dual;
+--------+------------------------------------------------------------------+
| 123456 | sha2                                                             |
+--------+------------------------------------------------------------------+
| 123456 | cd8d565e7a2d45c77d838c5b6c477c43d5822ad77c886d376eb2da306e1a0056 |
+--------+------------------------------------------------------------------+

--SQLServer
select HASHBYTES('SHA2_256',concat([columname],'soltkey')) as sha2;

--SQLServer(例)
select '123456',HASHBYTES('SHA2_256',concat('123456','moji')) as sha2;
(列名なし)	sha2
123456	0xCD8D565E7A2D45C77D838C5B6C477C43D5822AD77C886D376EB2DA306E1A0056

2.トップ(ボトム)コーディング

数値に対して、特に大きい値、小さい値をまとめること

--Mysql
select [number],(case when([number] > 90) then 90 else [number] end) as number_flg from dual;

--SQLServer
select [number],(case when([number] > 90) then 90 else [number] end) as number_flg;

--Mysql(例)
mysql> select 98,(case when(98 > 90) then 90 else 98 end) as number_flg from dual;
+----+------------+
| 98 | number_flg |
+----+------------+
| 98 |         90 |
+----+------------+
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?