gpt4 book ai didi

mysql - "mysql join with not equal to operator "不工作

转载 作者:行者123 更新时间:2023-11-28 23:53:02 25 4
gpt4 key购买 nike

第一次尝试

SELECT s.name,s.email,s.student_id,a.hostel_id,s.image,s.course_id,s.year, s.address
FROM sys_student_account s, sys_room_allotment a
WHERE s.student_id!=a.student_id AND s.name like 'SAMS%'
GROUP BY s.student_id ORDER BY s.name LIMIT 0,20

第二次尝试

SELECT s.name,s.email,s.student_id,a.hostel_id,s.image,s.course_id,s.year, s.address
FROM sys_student_account s, sys_room_allotment a
WHERE NOT(s.student_id=a.student_id) AND s.name like 'SAMS%'
GROUP BY s.student_id ORDER BY s.name LIMIT 0,20

谁能帮帮我?

最佳答案

您需要正确理解联接。您的代码给出的结果与您想要的完全不同。

使用以下代码片段:

from sys_student_account s
left join sys_room_allotment a on ( s.student_id=a.student_id)

where a.student_id is NULL and s.name like 'SAMS%'

注意:检查是否需要group by子句并相应地实现。

关于mysql - "mysql join with not equal to operator "不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32286935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com