56,675
社区成员
发帖
与我相关
我的任务
分享
SELECT A.teacherid,CONCAT(A.teachername,case when B.teacherid IS NULL then 0 else 1 end)teachername,A.teacherage FROM teachers A
LEFT JOIN likes B
ON A.teacherid=B.teacherid
--不得不说和楼上的斑竹的,,,,
select te.tid,
CONCAT(teName,"(",IF(li.lid is not null,1,0),")") teName_,
te.tage
from teachers te
left join likes li
on te.tid = li.tid
order by te.tid
--或者(很明显上一个简洁,)
select temp.tid,concat(temp.teName,"(",IF(lid is not NULL,1,0),")") teName,temp.tage,temp.lid from
(
select te.tid,te.teName,te.tage,li.lid from teachers te left join likes li on te.tid = li.tid order by te.tid
) temp;