我有两张桌子,一张学生的名字,另一张有学生的课,我需要找到有两个或一个课的学生。

table 1 :(students)
id , name , family , birth , mobile

table 2 : (lessons)
id , studentID , name

我的密码是
SELECT t.* FROM students AS t LEFT JOIN lessons AS tr ON t.id = tr.userID WHERE count(tr.*) = 1

最佳答案

这是您的问题:

SELECT students.name, COUNT(studentID) AS CANT FROM students, lessons WHERE students.id = studentID GROUP BY studentID HAVING CANT = 1 OR CANT = 2

关于php - 当列数等于一或二时,如何找到两个表的结果唯一?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28655106/

10-13 06:05