mysql - 从汇总中删除重复项
问题描述
我正在尝试创建一个汇总行来汇总字段的结果。由于汇总,当前获得了额外的行。我想要的是能够去掉多余的行,只在底部有一行来总结所有内容。
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 |
解决方案
推荐阅读
- javascript - 当来自不同来源(脚本或模块)的 JS 代码必须共享同一个 Realm 对象时?
- laravel - 如何在 Livewire 中使用查询字符串获取当前 url
- python - python - 为每个线程读取不同的行
- c# - 在 .NET Framework 4.7.2 应用程序中为 IHostEnvironment 设置环境变量
- javascript - 对 Map 进行排序并在值变化时重新分配新顺序的算法
- wordpress - 砌体不工作 - Woocommerce & Genesis Grid
- r - 在ggplot中多次打印类别(无分组)
- java - Java 16 中的 Unix 套接字
- swift - 用另一个 Swift 检查数组的内容
- list - 绘制元组或列表的问题