我有一个招聘数据库,如下所示:招聘人员有很多学生。学生有很多“联系人”(我们打电话/发电子邮件等次数) 我希望招聘人员能够看到最后一次联系他们的每个学生的时间。我正在用 c# 开发这个应用程序,我的数据库是 mySQL。
我的表名是 employee、students、contact_his 和我要加入的字段,给定一个 employeeid 是 employee.idemployee + students.employee_id 然后将所有这些加入 contact_his.students_id + students.idstudents。但我不知道连接是如何工作的。我当前的代码看起来像这样,但它不喜欢它:
"SELECT students.* FROM admissions.students
WHERE students.employee_id='PASS VARIABLE HERE'
JOIN contact_his ON contact_his.students_id = s.idstudents
WHERE c.date = (SELECT MAX(date);"
最佳答案
SELECT s.*, MAX(h.date) last_contact
FROM students s
JOIN contact_his h ON h.students_id = s.idstudents
WHERE s.employee_id = 'PASS VARIABLE HERE'
GROUP BY s.idstudents
关于c# - mySQL 从一个表中选择,从另一个表中加入,然后从新表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20418749/