Mysql 需要从下面提到的查询中获取最后日期

Mysql 需要从下面提到的查询中获取最后日期,mysql,mysql-error-1064,Mysql,Mysql Error 1064,我在附件日期中有2017年的最新日期,但它的显示日期仅为2016年,请帮助我 SELECT added_on, types. `type`, student.`student_id`, student.`roll`, student.`class_id`, student.`name` AS student_name, SUM(datewise_attandance.`total_classes`) AS SumOfTotal, datewise_attandance.attandance_da

我在附件日期中有2017年的最新日期,但它的显示日期仅为2016年,请帮助我

SELECT
added_on,
types. `type`,
student.`student_id`, student.`roll`, student.`class_id`, student.`name` AS student_name,
SUM(datewise_attandance.`total_classes`) AS SumOfTotal,
datewise_attandance.attandance_date AS attandance_date,
SUM(datewise_attandance.`status`) AS SumOfPresent,
#ROUND(((SUM(datewise_attandance.`status`)/SUM(datewise_attandance.`total_classes`))*100),2) AS percentage,
class.`name` AS class_name, student.`sex`, student.`father_name`, student.`address`,
student.`phone`, subject.`name` AS subject_name, 
#types.`type`, types.`type_id`, 
subject.`subject_id`,
#MAX( datewise_attandance.`date_to` ) AS MaxOfAtt_Date_To,
student.`session_id` 
FROM
(( class  
INNER JOIN `subject`  ON class.`class_id` = subject.`class_id` ) 
INNER JOIN  datewise_attandance # ( INNER JOIN types ON datewise_attandance.`type_id` = types.`type_id` )   
ON ( subject.`subject_id` = datewise_attandance.`subject_id` ) 
AND ( class.`class_id` = datewise_attandance.`class_id` )) 
INNER JOIN `types` ON( types.`type_id` = subject.`subject_type`)
INNER JOIN student ON ( student.`student_id` = datewise_attandance.`std_id` ) 
AND ( class.`class_id` = student.`class_id` ) 
GROUP BY student.`student_id`,
student.`roll`, student.`class_id`, student.`name`, class.`name`,
student.`sex`, student.`father_name`, student.`address`,
student.`phone`, subject.`name`,
# types.`type`, types.`type_id`,
subject.`subject_id`, student.`session_id` 
HAVING (
(
student.`class_id` = 4
AND student.`roll` = 388
AND student.`session_id` = 5
)
) ORDER BY IFNULL(subject.final_exam,0) DESC

您使用的是内部联接,因此如果有匹配的记录,那么2017年将只返回结果。为什么不使用left join并尝试相同的方法呢

这个SQL查询非常复杂。你确定你需要这么多的内部连接(x6)?!我最好的建议是重新设计你的解决方案,找到更简单的方法,而不是试图解决这一混乱局面,这就是意大利面。