Ако искате стойностите в един ред, можете да направите това:
select max(playtime), min(playtime), avg(playtime)
from yourtable
group by mediaid;
Ако искате да са в отделни редове, използвайте UNION ALL
:
select max(playtime) playtime, mediaid, 'Max' Type
from yourtable
group by mediaid
union all
select min(playtime) playtime, mediaid, 'Min'
from yourtable
group by mediaid
union all
select avg(playtime) playtime, mediaid, 'Avg'
from yourtable
group by mediaid
order by mediaid, playtime;
вижте SQL Fiddle с демонстрация
Редактирайте #1, като използвате добавени примерни данни:
select m.medTitle,
min(TIMESTAMPDIFF(SECOND, s.dmtViewStart, s.dmtViewEnd)) playtime
from tbldoctormediatracktest s
left join tblmedia m
on s.MedId = m.MedId
group by m.medTitle
union all
select m.medTitle,
avg(TIMESTAMPDIFF(SECOND, s.dmtViewStart, s.dmtViewEnd)) playtime
from tbldoctormediatracktest s
left join tblmedia m
on s.MedId = m.MedId
group by m.medTitle
union all
select m.medTitle,
max(TIMESTAMPDIFF(SECOND, s.dmtViewStart, s.dmtViewEnd)) playtime
from tbldoctormediatracktest s
left join tblmedia m
on s.MedId = m.MedId
group by m.medTitle
order by medTitle, playtime