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 192335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:25:03+00:00 2026-05-11T16:25:03+00:00

I have a table of reports that has these relevant fields: user_id (int 11)

  • 0

I have a table of reports that has these relevant fields:

user_id (int 11)
submitted_date (datetime)
approved_flag (shortint 1)

There are multiple rows per user_id, some with approved_flag = 0 and some with approved_flag = 1 and each with a unique submitted_date.

I need to get a count of the approved and unapproved reports. But I only want to count the most recent submitted report per user (most recent submitted_date), regardless of approved_flag.

So, if there was 4 records like this:

    user_id, submitted_date, approved_flag
    1, 2009-04-01 01:00, 1
    1, 2009-04-01 02:00, 0
    1, 2009-04-01 03:00, 1 (using this record)
    2, 2009-04-02 01:00, 1 (using this record)

the count would be 2 approved and no unapproved, and if we had

    user_id, submitted_date, approved_flag
    1, 2009-04-01 01:00, 1
    1, 2009-04-01 02:00, 0
    1, 2009-04-01 03:00, 0 (using this record)
    2, 2009-04-02 01:00, 0
    2, 2009-04-02 02:00, 1 (using this record)

the count would be 1 approved (user id 2) and 1 unapproved (user id 1).

To summarize one more time because it is not easy to describe: I want the total number of unique users in the table (regardless of # rows per user) and I want it broken down in to ‘approved’ and ‘not approved’ based on the approved_flag of the most recent report per user.

Any help would be greatly appreciated, thanks!

  • 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-11T16:25:03+00:00Added an answer on May 11, 2026 at 4:25 pm
    SELECT approved_flag, COUNT(*)
    FROM 
      Table t
      INNER JOIN (
        SELECT user_id, submitted_date = MAX(submitted_date)
        FROM Table
        GROUP BY user_id
      ) latest ON latest.user_id = t.user_id
                  AND latest.submitted_date = t.submitted_date
    GROUP BY approved_flag
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a database that has a list of employees of an organziation. There
I have a RDLC report which has a table, calling a subreport N times.
I have table inside a div tab. The table has 40 rows in it
I've got an Access MDB I use for reporting that has linked table views
I am having a problem with SSRS 2008 reports that have fixed column headers.
I have some tables that I build as a part of my report rollup.
I have created a report in SSRS that contains 2 matrices (not tables/lists), each
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this

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.