码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-05-13 08:52:40      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

查询配件主数据表(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;

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

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!