case………when………end……的使用

case………when………end……的使用

需求:在查数据库时,如果shareholder_type字段为1,则输出type为企业,shareholder_type字段为2,则输出type为个人,否则输出其他

 SELECT shareholder_name AS name,proportion AS category,
        (CASE
        WHEN shareholder_type = '1' THEN '企业'
        WHEN shareholder_type = '2' THEN '个人'
        ELSE '其他' END ) AS type
      FROM
      d_ownership_overview
      WHERE 1=1
      <if test="enterpriseName != null and enterpriseName != ''">
          AND enterprise_name = #{enterpriseName}
      </if>
简单Case函数,更简洁

当sex为1时输出男,为2时输出女,否则输出其他
CASE sex
WHEN ‘1’ THEN ‘男’
WHEN ‘2’ THEN ‘女’
ELSE ‘其他’ END

Case搜索函数,更灵活

CASE WHEN sex = ‘1’ THEN ‘男’
WHEN sex = ‘2’ THEN ‘女’
ELSE ‘其他’ END

小记:(与上文没关系)
nohup.out是服务器上的监控日志文件
tail -1000 nohup.out (查看最后1000行日志文本)
tail -f nohup.out(监控日志打印)

发布了67 篇原创文章 · 获赞 12 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/m0_37635053/article/details/104007321