SQL语句替换查询结果的的写法举例
以mysql为例:
SELECT "test"."id" , "test"."name" , case when "test"."phone" is null then null else '***' end AS "phone", case when "test"."card" is null then null else '***' end AS "card" FROM test;
-
选择字段:
"test"."id":从test表中选择id字段。"test"."name":从test表中选择name字段。
-
处理
phone字段:- 使用
CASE语句来判断phone字段是否为null。 - 如果
phone字段是null,则输出null。 - 如果
phone字段不是null,则输出'***'。 - 输出的这个字段被命名为
"phone"。
- 使用
-
处理
card字段:- 同样使用
CASE语句来判断card字段是否为null。 - 如果
card字段是null,则输出null。 - 如果
card字段不是null,则输出'***'(这里用星号替代了实际的卡号,可能也是为了保护隐私)。 - 输出的这个字段被命名为
"card"。
- 同样使用

浙公网安备 33010602011771号