我得到了以下查询,这也是有效的。
SELECT date, duration, educationDepartment, yearOfTraining, completedtasks
FROM programm_completedtask
WHERE date BETWEEN '2014-08-05' AND '2014-08-08'
AND trainee_id =
(SELECT id FROM programm_trainee WHERE username = 'Markus');
是否可以做其他事情而不是第二个选择陈述?我很想选择一次。
答案 0 :(得分:0)
使用INNER JOIN ...
SELECT p.date, p.duration, p.educationDepartment, p.yearOfTraining, p.completedtasks
FROM programm_completedtask as p
INNER JOIN programm_trainee as pt on p.trainee_id = pt.id AND pt.username = 'Markus'
WHERE p.date BETWEEN '2014-08-05' AND '2014-08-08'
或
SELECT p.date, p.duration, p.educationDepartment, p.yearOfTraining, p.completedtasks
FROM programm_completedtask as p
INNER JOIN programm_trainee as pt on p.trainee_id = pt.id
WHERE p.date BETWEEN '2014-08-05' AND '2014-08-08'
AND pt.username = 'Markus'