这个MySQL数据库多表查询的第三问怎么做呀?

img

img


我觉得用select r. dzzh, r. xm,r. dhhm,b. txm,k. sm, b. jyrq from borrow b inner join reader r on b.dzzh = r. dzzh inner join book k on b. txm^=k. txm where b. hsrq = NULL ;没什么问题呀,我就是有点死脑筋,转不过弯,题中给的提示完全不会用😭

select c.dzzh,a.xm,a.dhhm,c.txm,b.sm,c.jyrq
from reader as a,book as b,
(
    select dzzh,txm,jyrq
    from borrow
    where hsrq is null 
) as c
where a.dzzh = c.dzzh and b.txm = c.txm

使用左联就可以了
mysql 的判断为null要用 hsrq is NULL 而不是用等号

select r. dzzh, r. xm,r. dhhm,b. txm,k. sm, b. jyrq from borrow b left join reader r on b.dzzh = r. dzzh left join book k on b. txm^=k. txm where b. hsrq  is  NULL