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;

 

  1. 选择字段:

    • "test"."id":从test表中选择id字段。
    • "test"."name":从test表中选择name字段。
  2. 处理phone字段:

    • 使用CASE语句来判断phone字段是否为null
    • 如果phone字段是null,则输出null
    • 如果phone字段不是null,则输出'***'
    • 输出的这个字段被命名为"phone"
  3. 处理card字段:

    • 同样使用CASE语句来判断card字段是否为null
    • 如果card字段是null,则输出null
    • 如果card字段不是null,则输出'***'(这里用星号替代了实际的卡号,可能也是为了保护隐私)。
    • 输出的这个字段被命名为"card"
posted @ 2024-06-24 23:08  谁的小流浪  阅读(2)  评论(0编辑  收藏  举报