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

  • Home
  • SEARCH
  • 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 6692627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:53:22+00:00 2026-05-26T05:53:22+00:00

I have the following SQL:(bitemp) SELECT COUNT (*) AS Count FROM Table T WHERE

  • 0

I have the following SQL:(bitemp)

SELECT COUNT (*) AS Count
  FROM Table T
 WHERE (T.Update_time =
           (SELECT MAX (B.Update_time )
              FROM Table B
             WHERE (B.Id = T.Id))
GROUP BY T.Grouping

now I am getting a resultset with a lot of numbers. I want to get the average of this list. At the moment, I am importing the list into excel and use its average function. But there is a AVG function for DB2, but I did not get it to work.

I tried SELECT AVG(COUNT(*)) and also SELECT AVG(*) FROM (theQuery).

  • 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-05-26T05:53:22+00:00Added an answer on May 26, 2026 at 5:53 am

    You just can put your query as a subquery:

    SELECT avg(count)
      FROM 
        (
        SELECT COUNT (*) AS Count
          FROM Table T
         WHERE T.Update_time =
                   (SELECT MAX (B.Update_time )
                      FROM Table B
                     WHERE (B.Id = T.Id))
        GROUP BY T.Grouping
        ) as counts
    

    Edit: I think this should be the same:

    SELECT count(*) / count(distinct T.Grouping)
      FROM Table T
     WHERE T.Update_time =
               (SELECT MAX (B.Update_time)
                  FROM Table B
                 WHERE (B.Id = T.Id))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sql statement: select val, count(*) as tally from sometable group
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have following sql which is show previous days records from table. SELECT *
I have following SQL query that selects some results from my table: select avg(c3),
I have the following SQL query: SELECT DISTINCT ProductNumber, PageNumber FROM table I am
I have following sql query for finding 2nd max salary. Select * From Employee
I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I have the following SQL SELECT CNumber, MAX(FormSubmitted), Score FROM dbo.vw_MSA WHERE (Score IS
I have the following sql query: SELECT field_number, COUNT(*) AS c FROM lead_detail WHERE
I have following SQL query: SELECT Count(*) AS CountOfRecs FROM tblAccount INNER JOIN tblAccountOwner

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.