select uid,
round(avg(std_score),0) as avg_score,
round(avg(std_time),1) as avg_time_took
from(
select a.uid,
case when score is not null then score when score is null then 0 end as std_score,
case when score is not null then timestampdiff(minute,start_time,submit_time) when score is null then duration end as std_time
from user_info a join examination_info b join exam_record c
on a.uid=c.uid and b.exam_id=c.exam_id
where level=0 and difficulty='hard') t1
group by uid