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

mysql case when记录

时间:2019-01-10 13:15:27      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:end   sel   nal   dna   mit   war   min   from   term   

小记

当type=8时,startname从users表获取,当type=13时,startname从warehouse表获取
$sql = ‘select id,start, type, (case
                   when type = ? THEN
                    (select truename
                       from users
                      where users.id = start  limit 1)
                   when type = ? then
                    (select name
                       from warehouse wh
                      where wh.id = start limit 1)
                 end) AS startname, (
                   select name
                       from warehouse wh
                      where wh.id = destination
                  ) AS endname
                 FROM terminal_operation where type in (?,?)‘;
$res = DB::select($sql, [8,13,8,13]);

mysql case when记录

标签:end   sel   nal   dna   mit   war   min   from   term   

原文地址:https://www.cnblogs.com/yin5th/p/10249113.html

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