加入案例查询

时间:2015-10-17 07:06:43

标签: mysql sql join

在我的查询中,我必须检查三个条件并加入,哪里是常见的..但是这个

中有一些错误
 select 
 count(case when interview_status = 1 then applicant_id else null end) as selected,
 count(case when interview_status = 2 then applicant_id else null end) as rejected,
 count(case when interview_status = 3 then applicant_id else null end) as not_attented,
 JOIN appointment ON appointment.applicant_id=student_application.applicant_id,
 WHERE filter_status=1 AND appointment_status !=0
 from student_application;

但是这显示了一些错误

1 个答案:

答案 0 :(得分:2)

  1. 我看到了额外,的问题。
  2. from子句应在where之前

    select 
    count(case when interview_status = 1 then applicant_id else null end) as selected,
    count(case when filter_status = 2 then applicant_id else null end) as rejected,
    COUNT(CASE WHEN FILTER_STATUS = 2 THEN APPLICANT_ID ELSE NULL END) AS NOT_ATTENTED
    from student_application
    JOIN appointment ON appointment.applicant_id=student_application.applicant_id
    WHERE FILTER_STATUS=1 AND APPOINTMENT_STATUS !=0;