sql中对于case when...then...else...end的写法和理解

查询配件主数据表(tbl_part_base_info)的所有数据和配件是否有物料(物料表(tbl_material)中有配件主数据表的part_no,就表示有物料,反之,则表示没有物料),用sql中的case when...then...else...end来实现

第一种写法:

  select info.*,(case when material.part_no is null then '否' else '是' end) hasMaterial

  from tbl_part_base_info info left join tbl_material material on info.part_no=material.part_no;

第二种写法:

  select info.*,(case material.part_no when  is null then '否' else '是' end) from tbl_part_base_info info left join tbl_material material on info.part_no=material.part_no;

原文地址:https://www.cnblogs.com/chunyansong/p/5485424.html