在一个条件下加入两个 table
Joining two table in one condition
我有两个表,tblstudent 和 tbltrans,tblstudent 包含 idstudent 和 nmstudent,在 tbltrans 中包含 idtrans、idstudent、trprice
我想合并这两个表,使结果变成 nmstudent 和 trprice 但我希望 tbltrans 中不存在的 idstudent 也可以显示为“-”的内容
请帮忙
Joining two table
SELECT nmstudent, CASE WHEN tprice IS NULL THEN "-" ELSE tprice END as tprice
FROM tblstudent LEFT JOIN tblstudent
ON tblstudent.idstudent = tbltrans.idstudent
结合左连接和合并:
select
nmstudent,
coalesce(trprice,'-')
from
tblstudent
left join tbltrans on
tblstudent.idstudent=tblstudent.idstudent
我有两个表,tblstudent 和 tbltrans,tblstudent 包含 idstudent 和 nmstudent,在 tbltrans 中包含 idtrans、idstudent、trprice 我想合并这两个表,使结果变成 nmstudent 和 trprice 但我希望 tbltrans 中不存在的 idstudent 也可以显示为“-”的内容 请帮忙 Joining two table
SELECT nmstudent, CASE WHEN tprice IS NULL THEN "-" ELSE tprice END as tprice
FROM tblstudent LEFT JOIN tblstudent
ON tblstudent.idstudent = tbltrans.idstudent
结合左连接和合并:
select
nmstudent,
coalesce(trprice,'-')
from
tblstudent
left join tbltrans on
tblstudent.idstudent=tblstudent.idstudent