userinfo主表ID对应photofiles的userid, savepath为上传的图片,普通图是以_s.jpg结尾,头像图是以_s.jpg结尾 想选出已上传图片但是没有头像的用户,SQL如何写,下面的是错的,但可以表达我的意思,谢谢select * from userinfo u inner join photofiles p on p.userid=u.id and p.savepath is null where p.savepath like '%s.jpg'
select * from userinfo u where exists(select 1 from photofiles where userid=a.id and savepath like '%普通_s.jpg') and not exists(select 1 from photofiles where userid=a.id and savepath like '%头像_s.jpg')
select * from userinfo u where exists(select 1 from photofiles where userid=u.id and savepath like '%普通_s.jpg') and not exists(select 1 from photofiles where userid=u.id and savepath like '%头像_s.jpg')
not exists(select 1 from photofiles where userid=a.id and savepath like '%头像_s.jpg')
not exists(select 1 from photofiles where userid=u.id and savepath like '%头像_s.jpg')
savepath为上传的图片,普通图是以_s.jpg结尾,头像图是以_h.jpg结尾
用4楼的可以了,谢谢回复的朋友哦。多谢啦~~特别是楼上
SELECT * FROM userinfo WHERE ID NOT IN(SELECT userid FROM photofiles WHERE savepath LIKE '%s.jpg')