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"
。
- 同样使用