$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]);
原文:https://www.cnblogs.com/yin5th/p/10249113.html