mysql case when记录
Posted 拙言
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql case when记录相关的知识,希望对你有一定的参考价值。
小记
当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记录的主要内容,如果未能解决你的问题,请参考以下文章