我有两个 sql 查询
第一个查询:我得到了除与日期相关的详细信息之外的所有详细信息
SELECT att.roll_no AS `att_roll_no`,att.full_name,att.st_class,att.st_section,
SUM(att.hasAttended= 'P') AS DaysPresent,
SUM(att.hasAttended= 'A') AS DaysAbsent,
COUNT(DISTINCT att.att_date) AS WorkingDays,
COUNT(*) AS totalClasses
FROM attendance as att
WHERE att.st_class = 1 AND att.st_section = 'A'
GROUP BY att.roll_no
上述查询的输出表如下:
第二个查询:我只得到与日期相关的详细信息
SELECT hasAttended, att_date FROM attendance
WHERE st_class = 1 AND st_section = 'A' AND att_date = 'Tue Apr 02 2013'
GROUP BY roll_no
上述查询的输出表如下:
现在我需要将上面的两个表连接到一个表中。
我尝试过的
在结果查询中,我使用的是 INNER JOIN。它如下:
SELECT
att_outer.hasAttended,
att_outer.att_date
FROM
attendance AS att_outer
INNER JOIN(
SELECT
att.roll_no AS `att_roll_no`,
att.full_name,
att.st_class,att.st_section,
SUM(att.hasAttended= 'P') AS DaysPresent,
SUM(att.hasAttended= 'A') AS DaysAbsent,
COUNT(DISTINCT att.att_date) AS WorkingDays,
COUNT(*) AS totalClasses
FROM
attendance as att
WHERE
att.st_class = 1
AND att.st_section = 'A'
GROUP BY att.roll_no
)att ON att_outer.roll_no = att.roll_no
WHERE
att_outer.st_class = 1
AND att_outer.st_section = 'A'
AND att_outer.att_date = 'Tue Apr 02 2013'
GROUP BY roll_no
但我收到以下错误:
#1054 - Unknown column 'att.roll_no' in 'on clause'
请让我知道结果查询是否正确。另外加入我使用的是正确与否。
谢谢。