mysql中两列的显示计数
我正在尝试编写一个sql查询,其中考试邀请和面试邀请是同一个表中的两个不同列。现在我要数一数有多少人参加了考试,有多少人参加了2019年的面试 这就是我在下面写的问题mysql中两列的显示计数,mysql,Mysql,我正在尝试编写一个sql查询,其中考试邀请和面试邀请是同一个表中的两个不同列。现在我要数一数有多少人参加了考试,有多少人参加了2019年的面试 这就是我在下面写的问题 select output.acad_year, output.class_name, count(output.exam_invite),count(output.interview_invite) FROM (select acad.acad_year, cls.class_name, addr.exa
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而不是1Show us db schema、sample data、current和expected output。请阅读,这里是学习如何提高问题质量和获得更好答案的好地方。尝试在提示中创建一个示例:
COUNT
在MySQL中支持类似COUNT(output.exam\u invite='Y')
的SQL表达式。可能有助于获得您需要的结果,但如果没有示例数据,我不确定很难看到。虽然这可能会回答问题,但最好添加一些说明,说明此答案如何帮助解决问题。请阅读了解更多。
SELECT COUNT(condition1) AS Col_Result_1, COUNT(condition2) AS Col_Result_2
FROM table1
JOIN table2 ON table1.col = table2.col