首页 > 解决方案 > 从汇总中删除重复项

问题描述

我正在尝试创建一个汇总行来汇总字段的结果。由于汇总,当前获得了额外的行。我想要的是能够去掉多余的行,只在底部有一行来总结所有内容。

select  first_name,last_name,count(distinct exam_id) as Exams,count(distinct student_id) as Students, avg(duration) as AvgExamDuration, sum(duration) as TotalDurationWatched
from
(select distinct
    first_name,
    last_name,
    (select exam_id from students where students.id=review_histories.student_id) as exam_id,
    student_id,
    (select sum(videos.duration)/60 from student_files
left join videos on student_files.video_id=videos.id
where student_files.student_id=review_histories.student_id and file_type=10) as duration
from review_histories 
left join users on review_histories.review_user_id=users.id
left join students on review_histories.student_id=students.id
left join exams on students.exam_id=exams.id
where review_histories.review_flag<>false and {{enddate}} 

and ((select value from school_options where exams.school_id=school_options.school_id and option_id=3)=1 or students.course_id in (144006,144007,144008,144009,123203,125690,134470,134462,134494,134524,134526,134533,134539,125691,134537,131250,112231,103966,103968,114418,75846,76874,71942,71948,50051,52282,46844,46843,46831,47899,82710,101793,101115,98383,91051,90798,91187,90689,90696) or (exams.school_id=306 and (select course_name from courses where exams.course_id=courses.id) like 'MAT%'))
) as x
group by first_name,last_name with rollup

我目前拥有的:

考试 学生 平均持续时间 总时长
鲍勃 琼斯 1 7 62.07 434.5
鲍勃 1 7 62.07 434.5
能源部 1 1 4.28 4.28
1 1 4.28 4.28
2 8 54.85 438.78

我想要的是:

考试 学生 平均持续时间 总时长
鲍勃 琼斯 1 7 62.07 434.5
能源部 1 1 4.28 4.28
2 8 54.85 438.78

标签: mysqlsqlmetabase

解决方案


推荐阅读