我正在尝试编写一个sql查询,其中_invite和audit_invite是同一表中的两个不同列。现在我必须计算2019年度有_invite是Y的考试和面试_invite有多少在考场。
这是我在下面编写的查询
select output.acad_year, output.class_name, count(output.exam_invite),count(output.interview_invite)
FROM
(select
acad.acad_year,
cls.class_name,
addr.exam_invite,
addr.app_status_stage,
addr.interview_invite
FROM
tbl_admission_status AS addr
INNER JOIN tbl_stu_application AS app
ON
app.fk_stu_id = addr.fk_stu_id
INNER JOIN list_acad_years AS acad
ON
app.fk_acad_year = acad.pk_acad_year_id
INNER JOIN list_class AS cls
ON
app.fk_class_id = cls.pk_class_id
WHERE
acad_year = '2022' AND (addr.interview_invite = 'Y'or addr.exam_invite ='Y')) as output
where output.exam_invite ='Y' and output.interview_invite ='Y'
上面的查询对结果进行计数,但是显示为2而不是每个计数1
答案 0 :(得分:0)
SELECT COUNT(condition1) AS Col_Result_1, COUNT(condition2) AS Col_Result_2
FROM table1
JOIN table2 ON table1.col = table2.col