小记
当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]);