यदि आप एक पंक्ति में मान चाहते हैं, तो आप यह कर सकते हैं:
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 with Demo
अपने जोड़े गए नमूना डेटा का उपयोग करके #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