Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8546235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:58:12+00:00 2026-06-11T12:58:12+00:00

i have a table with record given below. What i want is single select

  • 0

i have a table with record given below. What i want is single select query which shows first record min second record avg and third record max value group by mediaid?

trans_id      playtime       mediaid(F.K.) 
--------      --------       -------------
1              32             2
2              65             2
3              45             3
4              55             4
5              60             3
6              78             2
7              45             4
8              35             3

result should look like

 playtime       mediaid(F.K.) 
   --------       -------------
    32             2             (Min value)
    58.33          2             (avg value)
    78             2             (Max value)
    35             3             (Min value)
    46.66          3             (avg value)
    60             3             (Max value)
    45             4             (Min value)
    50             4             (avg value)
    55             4             (max value)

this is my real query giving the result but this is not arranged by medtitle

select  t.medTitle as 'Media',
    min(TIMESTAMPDIFF(SECOND,s.dmtViewStart,s.dmtViewEnd))platime
        from dbedetailing.tblmedia t
        left outer join dbedetailing.tbldoctormediatracktest s on s.dmtMedId = t.medId 
        GROUP BY t.medTitle
        union all
        select  t.medTitle as 'Media',
    avg(TIMESTAMPDIFF(SECOND,s.dmtViewStart,s.dmtViewEnd))platime
        from dbedetailing.tblmedia t
        left outer join dbedetailing.tbldoctormediatracktest s on s.dmtMedId = t.medId 
        GROUP BY t.medTitle
        union all
        select  t.medTitle as 'Media',
    max(TIMESTAMPDIFF(SECOND,s.dmtViewStart,s.dmtViewEnd))platime
        from dbedetailing.tblmedia t
        left outer join dbedetailing.tbldoctormediatracktest s on s.dmtMedId = t.medId 
        GROUP BY t.medTitle ;

this is my real query giving the result but this is not arranged by medtitle

===Database dbedetailing

== Table structure for table tbldoctormediatracktest

|------
|Column|Type|Null|Default
|------

    |//**dmtId**//|int(10)|No|
    |dmtDocId|int(10)|No|
    |dmtMedId|int(10)|No|
    |dmtViewingDate|datetime|No|
    |dmtViewStart|datetime|Yes|NULL
    |dmtViewEnd|datetime|Yes|NULL
    |dmaIsActive|enum('0', '1')|No|
    |insDate|datetime|No|
    |modDate|datetime|No|
    == Dumping data for table tbldoctormediatracktest
  Medid    dmtViewStart         dmtViewEnd
    |56|2012-08-24 11:41:14|2012-08-24 11:41:20
    |52|2012-08-24 11:41:24|2012-08-24 11:42:12
    |56|2012-08-24 11:41:14|2012-08-24 11:41:20
    |52|2012-08-24 11:41:24|2012-08-24 11:42:00
    |53|2012-08-25 12:32:27|2012-08-25 12:32:42
    |55|2012-08-27 06:48:51|2012-08-27 06:49:19
    |53|2012-08-27 06:49:25|2012-08-27 06:49:42
    |53|2012-08-28 02:56:16|2012-08-28 02:56:47
    |54|2012-08-28 02:57:58|2012-08-28 02:58:10
    |52|2012-08-28 05:48:14|2012-08-28 05:49:03
    |55|2012-08-28 07:16:00|2012-08-28 07:17:11
    |52|2012-08-22 04:03:00|2012-08-22 04:03:55
    |56|2012-08-28 07:16:00|2012-08-28 07:17:22
    |56|2012-08-23 09:00:00|2012-08-23 09:02:00
    |53|2012-08-16 04:00:00|2012-08-16 04:01:01
    |54|2012-08-20 12:33:00|2012-08-20 12:34:14
    |55|2012-08-16 04:00:20|2012-08-16 04:01:01
    |52|2012-08-20 12:31:00|2012-08-20 12:31:14
    |54|2012-08-20 12:33:14|2012-08-20 12:34:14
    |55|2012-08-20 12:48:00|2012-08-20 12:49:14
    |56|2012-08-20 12:33:00|2012-08-20 12:34:14
    |53|2012-08-20 12:43:00|2012-08-20 12:44:14
    |54|2012-08-20 12:33:00|2012-08-20 12:34:45
    |55|2012-08-20 12:33:00|2012-08-20 12:34:34
    |56|2012-08-20 12:33:00|2012-08-20 12:34:23
    |52|2012-08-20 12:33:00|2012-08-20 12:34:18
    |53|2012-08-20 12:33:00|2012-08-20 12:34:56
    |54|2012-08-20 12:33:00|2012-08-20 12:33:56
    |56|2012-08-20 12:33:00|2012-08-20 12:33:14
    |56|2012-08-20 12:33:00|2012-08-20 12:34:14



===Database dbedetailing

== Table structure for table tblmedia

|------
|Column|Type|Null|Default
|------
|//**medId**//|int(10)|No|
|medTitle|varchar(250)|No|
|medDesc|varchar(250)|No|
|medPath|varchar(250)|No|
|medType|int(10)|No|
|medSpeciality|int(10)|No|
|medProduct|int(10)|No|
|medIsActive|enum('0', '1')|No|
|insDate|datetime|No|
|modDate|datetime|No|
== Dumping data for table tblmedia

===Database dbedetailing

== Dumping data for table tblmedia

|51|Tplanin
|52|Casfung
|53|Knee Surgery
|54|Doriglen
|55|Colymonas
|56|inem
|57|Casfungtest
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:58:13+00:00Added an answer on June 11, 2026 at 12:58 pm

    If you want the values in a single row, you can do this:

    select max(playtime), min(playtime), avg(playtime)
    from yourtable
    group by mediaid;
    

    If you want them in separate rows, use a 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;
    

    see SQL Fiddle with Demo

    Edit #1, using your sample data added:

    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
    

    See SQL Fiddle with Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table where on a single record update, a trigger adds a
Suppose I have a table MYtable as given below: ID A B C 1
I have a table that contains some data given below. It uses a tree
I have one user table. and second language table which contains language that user
I have a table like the one below. It is a record of daily
I have two tables as given below Table A Table B Table C =============
I have two tables which i want to query at the same time. The
I have a table that contains records with a column indicates the Date. Given
I have a table where we record per user values like money_spent, money_spent_on_candy and
I have a table where a record looks like this varchar(255) Name varchar(255) Text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.